PHP user registration Information validation regular expression _php tips

Source: Internet
Author: User
Tags strlen

The following method of verifying username is that the username must consist of a letter with a number of dashes, let's take a look at the example below.

1. Check that the user name is in accordance with the provisions of "more than two letters, numbers, or underline", the code is as follows:

/** 
 * Check User name compliance * * 
 @param STRING $username user name to check 
 * @return TRUE or FALSE/ 
function Is_ Username ($username) 
{ 
$strlen = strlen ($username); 
if (!preg_match ("/^[a-za-z0-9_\x7f-\xff][a-za-z0-9_\x7f-\xff]+$/", 
$username))//Open source software: phpfensi.com 
{ return 
false; 
} ElseIf (< $strlen | | | $strlen < 2) 
{return 
false; 
} 
return true; 

Two-digit letters, numbers, or underscores : ^[a-za-z0-9_\x7f-\xff][a-za-z0-9_\x7f-\xff]+$.

Note: Here, the letters are a-z,a-z, and the ASCII characters from 127 to 255 (0X7F-0XFF)

2, Password:6-20 digits, composed of letters, numbers, code as follows:

function Ispwd ($value, $minLen =5, $maxLen =16) { 
$match = '/^[\\~!@#$%^&* ()-_=+|{} \[\],.? \/:;\ ' \d\w]{'. $minLen. ', '. $maxLen. '} $/'; 
$v = Trim ($value); 
if (Emptyempty ($v)) return 
false; 
Return Preg_match ($match, $v); 

3, email verification , the code is as follows:

function Isemail ($value, $match = '/^[\w\d]+[\wd-.] *@[w\d-.] +\. [\w\d] {2,10}$/i ')

{ 
$v = trim ($value); 
if (Emptyempty ($v)) return 
false; 
Return Preg_match ($match, $v); 
} 


This article for everyone to share the user registration information: User name, password and the regular expression of the mailbox verification, I hope you seriously learn this "PHP user registration information validation Regular expression", will be harvested.

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.