In development, email address verification, url verification, and numbers are common examples. The following describes two verification email addresses, URLs, and digital programs written by different webmasters. For more information, see. In development, email address verification, url verification, and numbers are common examples. The following describes two verification email addresses, URLs, and digital programs written by different webmasters. For more information, see.
Script ec (2); script
Example
The Code is as follows: |
|
Public static function isEmail ($ email) { Return preg_match ("/^ (a-z0-9] * [-_ \.]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [\.] [a-z] {2, 4} ([\.] [a-z] {2 })? $/I ", $ email ); } Public static function isNumber ($ num) { Return is_numeric ($ num ); } Public static function isUrl ($ url, $ preg = false) { If ($ preg) { $ Status = preg_match ("/^ ([^: \/]) + \: \/[\ w-] + \. [\ w -.\? \/] + $/", $ Url ); } Else { $ Status = filter_var ($ url, FILTER_VALIDATE_URL ); } Return $ status; } |
Supplement: Use php built-in functions for operations.
Php verification email
The Code is as follows: |
|
$ Email = 'fengdingbo @ gmail.com '; $ Result = filter_var ($ email, FILTER_VALIDATE_EMAIL ); Var_dump ($ result); // string (20) "fengdingbo@gmail.com" |
Php url Verification
The Code is as follows: |
|
$ Url = "http://www.111cn.net "; $ Result = filter_var ($ url, FILTER_VALIDATE_URL ); Var_dump ($ result); // string (25) "http://www.111cn.net" |
Php IP address verification
The Code is as follows: |
|
$ Url = "192.168.1.110 "; $ Result = filter_var ($ url, FILTER_VALIDATE_IP ); Var_dump ($ result); // string (13) "192.168.1.110" // This method can also be used to verify ipv6. $ Url = "2001: DB8: 2de: e13 "; $ Result = filter_var ($ url, FILTER_VALIDATE_IP ); Var_dump ($ result); // string (17) "2001: DB8: 2de: e13" |