Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SImple Regex for valid email with Javascript

regex valid js update 2019

const validEmail(str) => !/(\.{2}|-{2}|_{2})/.test(val) && /^[a-z0-9][a-z0-9-_\.]+@([a-z]|[a-z0-9]?[a-z0-9-]+[a-z0-9])\.[a-z0-9]{2,10}(?:\.[a-z]{2,10})?$/.test(val);

validEmail('admin@gmail.com'); //true
validEmail('admin@my-large-domain.news'); //true
validEmail('admin@comercio.com.pe'); //true
validEmail('elonmusk@x.com'); // true (short domain)
validEmail('ud@se.cz'); // true (short domain)
validEmail('admin@mycompany.technology'); // true (large extension)
validEmail('.admin@gmail.com'); //false (not initial dot)
validEmail('admin--admin@gmail.com'); //false (not dashes followed)
validEmail('admin@-myapp-.com'); //false (not dashes initial and end)

more use cases: https://regex101.com/r/2ZKtyk/12/tests

@victorcunya

This comment has been minimized.

Copy link

commented May 22, 2018

Muy buena tu validación para correos electrónicos, no tienes una para Python porfa 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.