Php uses filter to verify mailbox ipv6 address url verification _ PHP Tutorial

Source: Internet
Author: User
Php uses the filter to verify the ipv6 address url of the mailbox. 1. verify email copy code: $ emailjb51@qq.com; $ resultfilter_var ($ email, FILTER_VALIDATE_EMAIL); var_dump ($ result); string (14) jb51@qq.com2, verify url location 1, verify email

The code is as follows:


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

2. verify the url address

The code is as follows:


$ Url = "http://www.jb51.net ";
$ Result = filter_var ($ url, FILTER_VALIDATE_URL );
Var_dump ($ result); // string (22) "http://www.jb51.net"

3. verify the IP address

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.

The code is as follows:


$ Url = "2001: DB8: 2de: e13 ";
$ Result = filter_var ($ url, FILTER_VALIDATE_IP );
Var_dump ($ result); // string (17) "2001: DB8: 2de: e13"

4. check whether the value is an integer within an integer range.

The code is as follows:


$ I = '010 ';
$ Result = filter_var (
$ I,
FILTER_VALIDATE_INT,
// Set the value range for verification
Array (
'Options' => array ('min _ range' => 1, 'max _ range' => 100)
)
);
Var_dump ($ result); // bool (false)

Php variables are of a weak type. If a filter is not used, it is true to use a variable greater than or less than the symbol.

The code is as follows:


$ I = '010 ';
$ Result = $ I >= 1 & $ I <= 100;
Var_dump ($ result); // bool (true)

5. verify floating point number

The code is as follows:


$ Float = 12.312;
$ Result = filter_var ($ float, FILTER_VALIDATE_FLOAT );
Var_dump ($ result); // float (12.312)

The authorization code is as follows: $ email = 'jb51 @ qq.com '; $ result = filter_var ($ email, FILTER_VALIDATE_EMAIL); var_dump ($ result); // string (14) "jb51@qq.com" 2. verify url location...

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.