php USES the filter filter to validate mailbox ipv6 address url authentication

  • 2020-11-26 18:44:11
  • OfStack

1. Verify the mailbox


$email = 'jb51@qq.com';
$result = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($result); //string(14) "jb51@qq.com" 

2. Verify the url address


$url = "https://www.ofstack.com";
$result = filter_var($url, FILTER_VALIDATE_URL);
var_dump($result); //string(22) "https://www.ofstack.com" 

3. Verify the ip address


$url = "192.168.1.110";
$result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); //string(13) "192.168.1.110" 

The value of 1 indicates that 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" 

4. Verify that the value is an integer and within 1 integer interval


$i = '010';
$result = filter_var(
    $i,
    FILTER_VALIDATE_INT,
    // Set the value range of the check 
    array(
      'options' => array('min_range' => 1, 'max_range' => 100)
    )
);
var_dump($result);//bool(false) 

The variable of php is weakly typed, which is true if you use the greater than or less than symbol judgment without a filter.


$i = '010';
$result = $i >= 1 && $i <= 100;
var_dump($result);//bool(true) 

5. Verify floating point Numbers


$float = 12.312;
$result = filter_var($float, FILTER_VALIDATE_FLOAT);
var_dump($result); //float(12.312)


Related articles: