找到此技术来验证电子邮件地址是否正确。
function check_email($email) {
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/',$email)) ) {
return true;
} else {
return false;
}
}
我是php的新手。这个大正则表达式命令意味着什么?
答案 0 :(得分:-1)
这个大正则表达式命令意味着什么?
模式#1细分:
Movies : A WALK,DRAGONBALL
Users : 1 20
Movies : JAMES BOND,MISSION
Users : 6 7
在我看来,第一种模式看起来像绝对无用的垃圾。
模式2细分:
/ #start of pattern delimiter
(@.*@) #Capture Group #1: match an @ sign, then zero or more (as many as possible) of any non-newline character, then another @ sign
| #or
(\.\.) #Capture Group #2: match a literal dot, then another literal dot
| #or
(@\.) #Capture Group #3: match an @ sign, then a literal dot
| #or
(\.@) #Capture Group #4: match a literal dot, then an @ sign
| #or
(^\.) #Capture Group #5: match the start of the string, then a literal dot
/ #end of pattern delimiter
我不推荐这些模式。
如果您要验证电子邮件,可以在StackOverflow周围使用更好的模式,或者您可以使用/ #start of pattern delimiter
^ #match start of string
.+ #match any non-newline character one or more times (as much as possible)
\@ #match @ (the \ is an escaping character which is not necessary)
(\[?) #Capture Group #1: match an opening square bracket zero or one time
[a-zA-Z0-9\-\.]+ #match one or more (as much as possible) of the following characters: lowercase letters, uppercase letters, digits, hyphens, and dots (the \ before the . is an escaping character which is not necessary)
\. #match a literal dot
( #start Capture Group #2
[a-zA-Z]{2,4} #match any uppercase or lowercase letter 2, 3, or 4 times
| #or
[0-9]{1,3} #match any digit 1, 2, or 3 times
) #end Capture Group #2
(\]?) #Capture Group #3: match a closing square bracket zero or one time
$ #match the end of the string
/ #end of pattern delimiter
电话。
研究这个字符串:
filter_var()