Regular Expressions 101

Community Patterns

Community Library Entry

5

Regular Expression
ECMAScript (JavaScript)

/
^([a-z0-9]+(?:[._-][a-z0-9]+)*)@([a-z0-9]+(?:[.-][a-z0-9]+)*\.[a-z]{2,})$
/
i

Description

CheckEmail Login start or end simbols [._- ] .login@domain.com - fail -login@domain.com - fail _login@domain.com - fail login.@domain.com - fail login-@domain.com - fail login_@domain.com - fail

Login double simbol [._-] login..name@domain.com - fail login--name@domain.com - fail login__name@domain.com - fail login_-name@domain.com - fail login_.name@domain.com - fail

Domain start or end simbol [.-] login@-domain.com - fail login@.domain.com - fail login@domain.com. - fail

Domain not march simbol [_] login@dom_ain.com - fail

Domain double simbol [.-] login@domain..com - fail login@domain--domain2.com - fail

Big subdomain login@dom1.dom2.dom-3.dom-4.com - good

Domain end two or more simbol login@domain.c - fail login@domain.ru - good

Login or domain can contain numbers 123login456@123domain456.com - good

<script> var reg = /^([a-z0-9]+(?:[._-][a-z0-9]+)*)@([a-z0-9]+(?:[.-][a-z0-9]+)*\.[a-z]{2,})$/i var result = reg.exec("login@domain.com"); //['login@domain.com', 'login', 'domain.com']; </script>
Submitted by Tikhonov Alexander <123546.90@mail.ru> - 9 years ago (Last modified a year ago)