PHP does not use regular verification email What's the big God

Source: Internet
Author: User
Condition 1: The first character must be English or numeric or underlined with which string function?
Condition 2: Must contain an @ STRING function Yes?
Condition 3: Contains more than one. Character
Conditional 4:@ characters before the.
Condition 5: Cannot end with @ or.
Condition 6: Length cannot be longer than 30 this knows with Mb_strlen


Reply to discussion (solution)

Would like to know, such an application scenario, what is more appropriate than the regular?

Would like to know, such an application scenario, what is more appropriate than the regular?



Character-by-word analysis is simple, and regular expressions seem concise but inefficient

Test the Client

 
  
 
 && $x < 123) | | ($x > && $x < 91) | | ($x > && $x < 58) | | $x = = 95) {//past the first pass $x1 = Strpos ($email, ' @ '), if ($x 1) {//past the second level $x2 = Strpos ($email, '. '); if ($x 2) {//pass the third pass if ($x 2 > $x 1) {//pass Fourth $s = substr ($email, strlen ($email) -1,1);//Load last character if ($s! = '. ' && $s! = ') {//After the fifth pass if (strlen ($email) < 30) {//After sixth off return True;}}}}} return false;} $test [] = ' Test qqq@qq.com '; $test [] = ' qqqqq.com '; $test [] = ' qqqqqcom '; $test [] = ' qqqqq. @com '; $test [] = ' qqqqq. @com @ '; $test [] = ' qqqqq. @com @. '; $test [] = ' 123456@qq.com. '; $test [] = ' 123456@qq.com '; $test [] = ' 123456@qq.comcomcomcomcomcomcomcomcomcomcomcom '; foreach ($test as $v) {echo $v; if ( Is_ok_email ($v)) {echo ' is the correct email ';} Else{echo ' is not the right email ';} Echo '
';}


Would like to know, such an application scenario, what is more appropriate than the regular?



Character-by-word analysis is simple, and regular expressions seem concise but inefficient



In fact, this is a kind of imagination, in the actual online environment because of the regular and affect the efficiency of the matter is almost nonexistent not only does not exist but improves the speed of development.

Thank you, great God, I know it's easy to use regular, I'm just practicing string functions

Idle practice practiced hand, not necessarily to

 
  {        return false;    }    $LB = $len-1;    $state = 0;    $dot _count = [0, 0];    for ($i = 0; $i < $len; $i + +)    {        $c = $s [$i];        if ($c = = '. ')        {            if ($i = = 0 | | $i = = $lb)            {                return false;            }            $dot _count[$state]++;        }        ElseIf ($c = = ' @ ')        {            if ($state! = 0 | | $i = = 0 | | $i = = $lb)            {                return false;            }            $state = 1;            Continue;        }    }    if ($dot _count[0] > 0 | | $dot _count[1] < 1)    {        return false;//according to landlord requirements,. appears before @ or not. Even after the @ is wrong    }    return true;} $x = ' 12@163com '; Var_dump (is_email_string ($x));


The above code is less to judge the other characters must be English or numeric or underline

 
  
 
 && $x < 123) | | ($x > && $x < 91) | | ($x > && $x < 58) | | $x = = 95) {//past the first pass $x1 = Strpos ($email, ' @ '), if ($x 1) {//past the second level $x2 = Strpos ($email, '. '); if ($x 2) {//pass the third pass if ($x 2 > $x 1) {//pass Fourth $s = substr ($email, strlen ($email) -1,1);//Load last character if ($s! = '. ' && $s! = ') {//After the fifth pass if (strlen ($email) < 30) {//After sixth off return True;}}}}} return false;} $test [] = ' Test qqq@qq.com '; $test [] = ' qqqqq.com '; $test [] = ' qqqqqcom '; $test [] = ' qqqqq. @com '; $test [] = ' qqqqq. @com @ '; $test [] = ' qqqqq. @com @. '; $test [] = ' 123456@qq.com. '; $test [] = ' 123456@qq.com '; $test [] = ' 123456@qq.comcomcomcomcomcomcomcomcomcomcomcom '; foreach ($test as $v) {echo $v; if ( Is_ok_email ($v)) {echo ' is the correct email ';} Else{echo ' is not the right email ';} Echo '
';}




Big God, just found a problem, Strpos is to find the first occurrence of the string location for example, I enter an address: 123@qq.@.con This will also pass OH.

One more, you can keep improving.

 () {return false;    } $lb = $len-1;    $state = 0;    $dot _count = [0, 0];        for ($i = 0; $i < $len; $i + +) {$c = $s [$i];        if ($c = = '. ')            {if ($i = = 0 | | $i = = $lb) {return false;        } $dot _count[$state]++; } elseif ($c = = ' @ ') {if ($state! = 0 | | $i = = 0 | | $i = = $lb) {retur            n false;            } $state = 1;        Continue } elseif (! ( $c = = ' _ ' | | ($c >= ' a ' && $c <= ' z ') | | ($c >= ' A ' && $c <= ' Z ') | |        ($c >= ' 0 ' && $c <= ' 9 ')))        {return false;    }} if ($dot _count[0] > 0 | | $dot _count[1] < 1) {return false; } return true; $x = ' 12@163.com '; Var_dump (is_email_string ($x));

Condition 1: The first character must be English or numeric or underlined with which string function?
if ($email {0} = = ' _ ' | | ($email {0} >= ' 0 ' && $email {0} <=9) | | (Strtoupper ($email {0}) >= ' A ' | | | strtoupper ($email {0}) <= ' Z ')

Condition 2: Must contain an @ STRING function Yes?
if (Substr_count ($email, ' @ ') = = 1)

Condition 3: Contains more than one. Character
if (Substr_count ($email, '. ') >= 1)

Conditional 4:@ characters before the.
if (Strpos ($email, ' @ ') < Strpos ($emai, '. '))

Condition 5: Cannot end with @ or.
if (substr ($email,-1)! = ' @ ' && substr ($email,-1)! = '. ')

Condition 6: Length cannot be longer than 30 this knows with Mb_strlen
if (strlen ($eamil) <= 30)

Judging these, in fact, do not have to one item, they can be linked together, the idea is not too narrow.
If you must use a variety of functions, such as explode (' @ ', $email), the resulting array length is two description must have only one @, and then simply judge the contents of two elements, you can achieve the purpose.

The great God is the great God.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.