Php url address email IP Address Verification

Source: Internet
Author: User

Php Tutorial url address email Address Verification
Previously, we used regular expressions to verify email addresses, ip addresses, and url addresses. Now we use three functions: php filter_validate_url, filter_validate_email, and filter_validate_ip.
Filter_validate_url uses the value as the url for verification.
Filter_validate_email uses the value as email for verification.
Filter_validate_ip uses the value as the ip address for verification.

*/

$ Url = "example. php? Name = peter & age = 37 ";

If (! Filter_var ($ url, filter_validate_url, filter_flag_query_required ))
{
Echo "url is not valid ";
}
Else
{
Echo "url is valid ";
}

/*
The filter_validate_email filter uses the value as the email address for verification.
*/

$ Email = "someone @ exa mple.com ";

If (! Filter_var ($ email, filter_validate_email ))
 {
Echo "e-mail is not valid ";
 }
Else
 {
Echo "e-mail is valid ";
 }

/*
The filter_validate_ip filter verifies the value as an ip address.
*/
$ Ip = "192.168.0.1 ";

If (! Filter_var ($ ip, filter_validate_ip ))
 {
Echo "ip is not valid ";
 }
Else
 {
Echo "ip is valid ";
 }
 
// Ipv6
 
$ Ip = "2001: 0db8: 85a3: 08d3: 1319: 8a2e: 0370: 7334 ";

If (! Filter_var ($ ip, filter_validate_ip, filter_flag_ipv6 ))
 {
Echo "ip is not valid ";
 }
Else
 {
Echo "ip is valid ";
 }

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.