1, verify the mailbox
Copy Code code as follows:
$email = ' jb51@qq.com ';
$result = Filter_var ($email, Filter_validate_email);
Var_dump ($result); String "Jb51@qq.com"
2. Verify URL Address
Copy Code code as follows:
$url = "Http://www.jb51.net";
$result = Filter_var ($url, Filter_validate_url);
Var_dump ($result); String (http://www.jb51.net)
3. Verify IP Address
Copy Code code as follows:
$url = "192.168.1.110";
$result = Filter_var ($url, FILTER_VALIDATE_IP);
Var_dump ($result); String (13) "192.168.1.110"
Value, this method can also be used to validate IPv6.
Copy Code code as follows:
$url = "2001:db8:2de::e13";
$result = Filter_var ($url, FILTER_VALIDATE_IP);
Var_dump ($result); String (2001:DB8:2DE::E13)
4, verify that the value is an integer, and within an integer interval
Copy Code code as follows:
$i = ' 010 ';
$result = Filter_var (
$i,
Filter_validate_int,
Set the value range of the checksum
Array
' Options ' => array (' Min_range ' => 1, ' Max_range ' => 100)
)
);
Var_dump ($result);//bool (false)
PHP variable is a weak type, if not the filter, the direct use of greater than the symbol of less than the word will be true.
Copy Code code as follows:
$i = ' 010 ';
$result = $i >= 1 && $i <= 100;
Var_dump ($result);//bool (True)
5. Verifying floating point numbers
Copy Code code as follows:
$float = 12.312;
$result = Filter_var ($float, filter_validate_float);
Var_dump ($result); Float (12.312)