Skip to content

Instantly share code, notes, and snippets.

@basarat
Created September 14, 2018 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basarat/dcb7bfb90e71fa46d89b6a13e8d58476 to your computer and use it in GitHub Desktop.
Save basarat/dcb7bfb90e71fa46d89b6a13e8d58476 to your computer and use it in GitHub Desktop.
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