An instance of a regular expression that matches the email address in PHP, and the email address replaces the regular matching expression I used most often:/^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\\.] [A-z] {2,3} ([\\.] [A-z] {2})? $/i, the following to detailed analysis of the needs of friends can be consulted.
PHP Example
The following is a description of PHP as an example:
The code is as follows |
Copy Code |
< PHP if (Ereg ("/^[a-z") ([A-z0-9]*[-_.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[.] [A-z] {2,3} ([.] [A-z] {2})? $/i; ", $email)) { echo "Your email address is correct!"; } Else { echo "Please try again!"; } ?> |
Description
①/content/I forms a case-insensitive regular expression; ^ match starts; $ match ends.
②[A-Z] e-mail prefix must be an English letter beginning
③ ([a-z0-9]*[-_]?[ a-z0-9]+) * and _a_2, AAA11, _1_a_2 matches, and a1_, Aaff_33a_, A__aa do not match, if it is a null character, is also matched, * represents 0 or more.
A ④* represents 0 or more preceding characters.
⑤[a-z0-9]* match 0 or more English letters or numbers; [-_]? Match 0 or 1 "-" because "-" cannot appear consecutively.
⑥[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be the end
⑦@ must have a @
⑧ ([a-z0-9]*[-_]?[ a-z0-9]+) + See above ([a-z0-9]*[-_]?[ a-z0-9]+) * explanation, but cannot be empty, + denotes one or more.
⑨[.] Add special characters (.) As ordinary characters, [a-z]{2,3} matches 2 to 3 English letters, usually COM or net.
⑩ ([.] [A-z] {2})? Match 0 or 1 [.] [A-z] {2} (e.g.. CN, etc.) I don't know the general. Com.cn the last part is not all two-bit, if not please modify {2} to {start Word, end Word}
JS Example
The code is as follows |
Copy Code |
|
To give you a better grasp of the regular, learn the string escape form
Here, you use a string to represent the regular, the escape character to be represented by \, and if you want to match, use \
^\w+@\w+\.\w+ (\.\w+) *$
Start is W word has one or more
@ After
is a word
. After a word has one or more
(\.\w+) * can have no or more
http://www.bkjia.com/PHPjc/633085.html www.bkjia.com true http://www.bkjia.com/PHPjc/633085.html techarticle an instance of a regular expression that matches the email address in PHP, and the email address replaces the regular matching expression I used most often:/^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\\.] [A-Z ...