Judge a regular expression of the email and explain the meaning of the regular expression one by one.
The code is as follows: |
Copy code |
^ (W + (-w +) | (. w +) *) + w + (-w +) | (. w +) * @ [A-Za-z0-9] + ((. |-) [A-Za-z0-9] + )*. [A-Za-z0-9] + $ |
^ Match the string header
(W + (-w +) | (. w +) *) 1: match strings such as laidfj456, sfi-lsoke, and fe.23i.
+ Match the plus sign
W + (-w +) | (. w +) * same as 1
@ Matched @
[A-Za-z0-9] + 2: consisting of upper and lower case letters and numbers? Is equivalent to w +.
(. |-) [A-Za-z0-9] +) * matches 0 or multiple strings starting with "." or "-", such as. oeiu234mJ,-oiwuer4
. Match "."
[A-Za-z0-9] + same 2
$ Matching string? Tail
Instance
The code is as follows: |
Copy code |
<? Php /** * Regular expression @ author: lijianghai */ Function isEmail ($ input = null) {// Username: composed of numbers, letters, and strip; $ Email = $ input; /* Use preg_ereg () error: because the second parameter needs to be an array * If (preg_grep ("^ [a-zA-Z] [a-zA-Z0-9 _] {} @ [0-9A-Za-z }(.) (com | cn | net | com.cn) $ ", array ($ input ))) { Echo $ email. 'Is a qualified email address '; } Else { Echo $ email. 'Format error '; } */ If (ereg ("^ [a-zA-Z] [a-zA-Z0-9 _] {} @ [0-9a-zA-Z }(.) (com | cn | com.cn | net) $ ", $ email )) { Echo $ email. "compliant with the format specifications "; } Else { Echo $ email. 'Format error '; } } $ Email = ""; IsEmail ($ email ); ?> |