PHP uses the filter filter to verify mailbox IPv6 address URL validation _php tutorial

Source: Internet
Author: User
1, verify the mailbox

Copy the Code code as follows:
$email = ' jb51@qq.com ';
$result = Filter_var ($email, Filter_validate_email);
Var_dump ($result); String "Jb51@qq.com"

2. Verify the URL address

Copy the 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 the 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"

As a value, this method can also be used to verify the IPv6.

Copy the 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 range

Copy the 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 is a weak type, if you do not use a filter, directly using greater than the less than the symbol will be true.

Copy the Code code as follows:
$i = ' 010 ';
$result = $i >= 1 && $i <= 100;
Var_dump ($result);//bool (True)

5. Verifying floating-point numbers

Copy the Code code as follows:
$float = 12.312;
$result = Filter_var ($float, filter_validate_float);
Var_dump ($result); Float (12.312)

http://www.bkjia.com/PHPjc/621664.html www.bkjia.com true http://www.bkjia.com/PHPjc/621664.html techarticle 1. Verify the code of the mailbox copy code as follows: $email = ' jb51@qq.com '; $result = Filter_var ($email, Filter_validate_email); Var_dump ($result);//s Tring (+) "jb51@qq.com" 2, verify URL to ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.