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.