Verification of email and other formats in php-PHP source code

Source: Internet
Author: User
This article will introduce some of my frequently-used regular expressions in formats such as emailtel. This article will introduce some of my frequently-used regular expressions in email, tel, and other formats.

Script ec (2); script

1. email verification function

The Code is as follows:

Function isValidEmail ($ email ){

$ Email = strtolower ($ email );
If (! Preg_match ("/[^ @] {1,255} @ [^ @] {}/", $ email )){
Return false;
}
$ Email_array = explode ("@", $ email );
$ Local_array = explode (".", $ email_array [0]);
$ Length = sizeof ($ local_array );
For ($ I = 0; $ I <$ length; $ I ++ ){
If (! Preg_match ("@ ^ [a-z0-9 _~ -] [A-z0-9 _~. -] {0, 63 }$ @ ", $ local_array [$ I]) {
Return false;
}
}
Unset ($ length );
If (! Preg_match ("@ ^ [? [0-9.] +]? $ @ ", $ Email_array [1]) {

$ Domain_array = explode (".", $ email_array [1]);

$ Length = sizeof ($ domain_array );
If ($ length <2 ){
Return false;
}
For ($ I = 0; $ I <$ length; $ I ++ ){
If (! Preg_match ('/^ ([a-z0-9] [a-z0-9-] {} [a-z0-9]) | ([a-z0-9] +) $ /", $ domain_array [$ I]) {
Return false;
}
}
Unset ($ length );
}
Return true;
}


2. Verify that the mobile phone number complies with the specifications

The Code is as follows:

Function isValidCellPhone ($ cellPhone ){

$ Flag = FALSE;

If (preg_match ('@ ^ 1 [3458] [0-9] {9} $ @', $ cellPhone )){

$ Flag = TRUE;

}

Return $ flag;

}

3. Verify that the phone number complies with the specifications

The Code is as follows:

Function isValidPhone ($ phone ){

If (preg_match ('@ ^ 1 [3458] [0-9] {9 }$ @', $ phone )){

Return true;

}

If (preg_match ('@((? :(? :(? : 00860? | 0 )(? : 10 | 2d | [3-9] dd ))-?)? ([2-8] d {6, 7}) @ ', $ phone )){

Return true;

}

If (preg_match ('@ ^ ([48] 00 (? : D {7} |-d {7} |-d {3}-d {4} |-d {4}-d {3} | d-d {3 }- d {3 })) $ @ ', $ phone )){

Return true;

}

Return false;

}

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.