Php uses the filter function to verify the mailbox, url, and IP address

Source: Internet
Author: User
Tags integer numbers

In php programs, regular expressions are generally used to verify email addresses, IP addresses, and URLs. In fact, some Built-in validation rules are provided in php. The following example describes how to use the built-in filter function of php to verify email, ip, and URL.

1. verify email

$ Email = 'phpernote @ 163.com '; $ result = filter_var ($ email, FILTER_VALIDATE_EMAIL); var_dump ($ result); // output: string (17) 'phpernote @ 163.com'

2. Verify the url address

$ Url = 'HTTP: // www.phpernote.com/'; $ result = filter_var ($ url, FILTER_VALIDATE_URL); var_dump ($ result); // output: string (25) 'HTTP: // www.phpernote.com /'

3. Verify the IP address

$ Url = '192. 168.0.1 '; $ result = filter_var ($ url, FILTER_VALIDATE_IP); var_dump ($ result); // output: string (11) '192. 168.0.1'

The filter function in php can also be used to verify floating-point numbers, integer numbers, and Boolean types. For details, refer to the filter function in the php manual or refer to the following article on this site:

PHP filter_var () function Filter function

Articles you may be interested in
  • Common JS function collection (remove spaces, verify email addresses, dates, positive integers, etc)
  • PHP filter_var () function Filter function
  • Php uses array_flip to implement array key-value exchange to remove array duplicate values
  • Collect common php functions with explanations
  • PHP string escape functions (addslashes, stripslashes)
  • Php performance optimization: Using isset () to determine the string length is faster than strlen ()
  • Use the PHP function memory_get_usage to obtain the current PHP memory consumption for program performance optimization.
  • URL encoding functions such as urlencode (), urldecode (), rawurlencode (), and rawurldecode ()

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.