Created
September 14, 2018 00:39
-
-
Save basarat/dcb7bfb90e71fa46d89b6a13e8d58476 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Validator } from 'formstate'; | |
export const email: Validator<string | null | undefined> = (value: string | null | undefined) => { | |
if (value == null || value == '') return null; | |
value = value.trim(); | |
// src : http://emailregex.com/ | |
if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/g.exec(value)) { | |
return "Not a valid email address"; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment