PHP Verification Mailbox and IP address the simplest way to summarize _php tips

Source: Internet
Author: User
Tags preg

Verification in the development of mailboxes, URLs, numbers are some of our common examples, the following sorting out the verification of mailboxes, URLs, digital programs, we are interested to refer to.

The example code is as follows:

public static function Isemail ($email) 
{return 
preg_match/^ ([a-z0-9]*[-_\.]? [a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,4} ([\.] [A-z] {2})? $/i ", $email); 
} 
public static function Isnumber ($num) 
{return 
is_numeric ($num); 
} 
The public static function Isurl ($url, $preg = False) 
{ 
if ($preg) 
{ 
$status = Preg_match ("/^" ([^:\/\/ ]) +\:\/\/[\w-]+\.[\w-.\?\/]+$/", $url); 
} 
else 
{ 
$status = Filter_var ($url, Filter_validate_url); 
return $status; 

add: use PHP to operate with its own functions.

PHP verification Mailbox, the code is as follows:

$email = ' fengdingbo@gmail.com ';             
$result = Filter_var ($email, filter_validate_email); 
Var_dump ($result); String (fengdingbo@gmail.com) 

PHP authentication URL address, the code is as follows:

$url = "Http://www.jb51.net"; 
$result = Filter_var ($url, filter_validate_url); 
Var_dump ($result); String (http://www.jb51.net) 

PHP Authentication IP Address, the code is as follows:

$url = "192.168.1.110"; 
$result = Filter_var ($url, filter_validate_ip); 
Var_dump ($result); String (192.168.1.110) 
//This method can also be used to validate IPv6. 
$url = "2001:db8:2de::e13";              
$result = Filter_var ($url, filter_validate_ip); 
Var_dump ($result); String (2001:DB8:2DE::E13)

The above is PHP verification mailbox and IP address the simplest way, I hope to help you learn.

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.