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; } |