Php user registration information validation regular expression

Source: Internet
Author: User
Various web scripts also use regularexpressions to verify our information and determine whether it is legal. This article introduces php user registration and verification regular expressions, if you need a user, refer to the following regular expression to verify the user name. The principle is that the user name must be composed of a sequence with a fixed number. let's take a look at the example below.

1. check the user nameWhether it meets the "two or more letters, numbers, or underscores" requirement. the code is as follows:

/*** Check whether the user name meets the requirements ** @ param STRING $ username the user name to be checked * @ 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 (20 <$ strlen | $ strlen <2) {return false;} return true ;}

Two or more letters, numbers, or underscores: ^ [A-zA-Z0-9 _ \ x7f-\ xff] [a-zA-Z0-9 _ \ x7f-\ xff] + $.

Note: Here the letter is a-z, A-Z, and ASCII characters from 127 to 255 (0x7f-0xff)

2. password:It consists of 6 to 20 digits and consists of letters and numbers. the code is 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 verificationThe 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 will share with you the user registration information: username, password, and regular expression for mailbox verification. I hope you will learn this article carefully, the regular expression for verifying php user registration information.

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.