Perfect email verification regular expression

Time:2020-11-18

The format of international domain name is as follows:
The domain name is composed of any combination of the specific character set, English letters, numbers and “-” (i.e. hyphen or minus sign), but the beginning and end of the domain name can not contain “‘”, and “-” cannot appear continuously. Letters in domain names are not case sensitive. Domain names can be up to 60 bytes (including suffixes. Com,. Net,. Org, etc.).

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

/Content / I constitutes a case insensitive regular expression;
^Match start
$match end
[A-Z] e-mail prefix must start with an English letter

([a-z0-9]*[-_ ]? [a-z0-9] +) * and_ A_ 2、aaa11、_ 1_ A_ 2 match, and A1_ 、aaff_ 33a_ 、a__ AA does not match. If it is a null character, it is also matched, * means 0 or more.
*Represents 0 or more preceding characters
[a-z0-9] * matches 0 or more English letters or numbers
[- ]? matches 0 or 1 “- because” – “cannot appear consecutively
[a-z0-9] + matches one or more English letters or numbers because ‘-‘ cannot be used as the end

@There must be [email protected]
([a-z0-9]*[-_ ]? [a-z0-9] +) + see above ([a-z0-9]*[-_ ]? [a-z0-9] +) * but cannot be empty, + means one or more.
[\.] treat special characters (.) as normal characters
[A-Z] {2,3} matches two to three English letters, usually com or net
([\. [A-Z] {2})? Matching 0 or 1 [\. [A-Z] {2} (e.g. CN, etc.) I don’t know com.cn If not, please change {2} to {start word, end word}

Recommended Today

PHP 12th week function learning record

sha1() effect sha1()Function to evaluate the value of a stringSHA-1Hash. usage sha1(string,raw) case <?php $str = “Hello”; echo sha1($str); ?> result f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 sha1_file() effect sha1_file()Function calculation fileSHA-1Hash. usage sha1_file(file,raw) case <?php $filename = “test.txt”; $sha1file = sha1_file($filename); echo $sha1file; ?> result aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d similar_text() effect similar_text()Function to calculate the similarity between two strings. usage similar_text(string1,string2,percent) case […]