Verification in the development of mailboxes, URLs, numbers are some of our common examples, the following sorting out the verification of mailboxes, URLs, digital programs, we are interested to refer to.
The example 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);
}
The 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;
add: use PHP to operate with its own functions.
PHP verification Mailbox, the code is as follows:
$email = ' fengdingbo@gmail.com ';
$result = Filter_var ($email, filter_validate_email);
Var_dump ($result); String (fengdingbo@gmail.com)
PHP authentication URL address, the code is as follows:
$url = "Http://www.jb51.net";
$result = Filter_var ($url, filter_validate_url);
Var_dump ($result); String (http://www.jb51.net)
PHP Authentication IP Address, the code is as follows:
$url = "192.168.1.110";
$result = Filter_var ($url, filter_validate_ip);
Var_dump ($result); String (192.168.1.110)
//This method can also be used to validate IPv6.
$url = "2001:db8:2de::e13";
$result = Filter_var ($url, filter_validate_ip);
Var_dump ($result); String (2001:DB8:2DE::E13)
The above is PHP verification mailbox and IP address the simplest way, I hope to help you learn.