Skip to content

Instantly share code, notes, and snippets.

@OscarGM40
Forked from Klerith/is-valid-email.ts
Created February 13, 2022 16:50
Show Gist options
  • Save OscarGM40/606f5664d6f40e6b3e82956cb1bc37c9 to your computer and use it in GitHub Desktop.
Save OscarGM40/606f5664d6f40e6b3e82956cb1bc37c9 to your computer and use it in GitHub Desktop.
Email validation - customHook
const isValidEmail = ( email: string ) => {
const re = /^(([^<>()[\]\\.,;:\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,}))$/;
return re.test(email);
}
@OscarGM40
Copy link
Author

La constante re es de tipo RegExp,es una interface de Typescript con varias funciones como test o exec para comprobar o ejecutar expresiones regulares.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment