Home > Backend Development > PHP Tutorial > Summary of commonly used test function examples when registering PHP users, PHP user registration_PHP tutorial

Summary of commonly used test function examples when registering PHP users, PHP user registration_PHP tutorial

WBOY
Release: 2016-07-13 10:11:06
Original
907 people have browsed it

A summary of commonly used test function examples for php user registration, php user registration

The examples in this article summarize the commonly used verification functions when registering PHP users. Share it with everyone for your reference. The specific analysis is as follows:

A summary of some common test functions commonly used when PHP users register, including testing whether the submitted data conforms to the user name format, testing whether the parameter values ​​are the same, testing whether the parameters are in Chinese, testing whether the email address is correct, and testing whether the parameters are For numbers, etc., these verifications before submitting to the database are commonly used in regular expressions. Here is a summary of some commonly used test parameter types. They can be used as a whole, or you can select some commonly used ones. .

Copy code The code is as follows:
/**
* Check detection class
*/
Class Check{
/**
* IsUsername function: Check whether it matches the username format
* $Argv is the username parameter to be detected
* $RegExp is the regular statement to be tested
* Return value: Return the user name according to the user name format, not return false
​*/
function IsUsername($Argv){
$RegExp=/^[a-zA-Z0-9_]{3,16}$/; //It consists of uppercase and lowercase letters and numbers and the length is 3-16 characters directly
Return preg_match($RegExp,$Argv)?$Argv:false;
}
                                   
/**
* IsMail function: Check whether the email format is correct
* Return value: Return the email in the correct email format, not return false
​*/
function IsMail($Argv){
$RegExp=/^[a-z0-9][a-z.0-9-_] @[a-z0-9_-] (?:.[a-z]{0,3}.[a-z]{0,2 }|.[a-z]{0,3}|.[a-z]{0,2})$/i;
Return preg_match($RegExp,$Argv)?$Argv:false;
}

/**
* IsSmae function: Check whether the values ​​of parameters are the same
* Return value: true if the same, false if not the same
​*/
function IsSame($ArgvOne,$ArgvTwo,$Force=false){
return $Force?$ArgvOne===$ArgvTwo:$ArgvOne==$ArgvTwo;
}
                                   
/**
* IsQQ function: Check whether the parameter value conforms to the format of QQ number
* Return value: Return the QQ number if it is the correct QQ number, not false
​*/
function IsQQ($Argv){
$RegExp=/^[1-9][0-9]{5,11}$/;
Return preg_match($RegExp,$Argv)?$Argv:false;
}
                                   
/**
* IsMobile function: Check whether the parameter value is the correct Chinese mobile phone number format
* Return value: Return the correct mobile phone number, not return false
​*/
function IsMobile($Argv){
$RegExp=/^(?:13|15|18)[0-9]{9}$/;
Return preg_match($RegExp,$Argv)?$Argv:false;
}
                                   
/**
* IsTel function: Check whether the value of the parameter is the correct Chinese phone number format including the area code
* Return value: Return the correct phone number, not false
​*/
function IsTel($Argv){
$RegExp=/[0-9]{3,4}-[0-9]{7,8}$/;
Return preg_match($RegExp,$Argv)?$Argv:false;
}
                                   
/**
* IsNickname function: Check whether the parameter value is in the correct nickname format (Beta)
* Return value: Return the nickname format if it is the correct nickname format, if not return false
​*/
function IsNickname($Argv){
$RegExp = '/^s*$|^c:concon$|[%,*"st<>&'()]|xA1xA1|xACxA3|^Guest|^xD3xCExBFxCD|xB9x43xABxC8/is'; //Copy From DZ
Return preg_match($RegExp,$Argv)?$Argv:false;
}
                                   
/**
* IsChinese function: detects whether the parameter is Chinese
* Return value: It is a return parameter, not false
​*/
function IsChinese($Argv,$Encoding=utf8){
$RegExp = $Encoding==utf8?/^[x{4e00}-x{9fa5}] $/u:/^([x80-xFF][x80-xFF]) $/;
Return preg_match($RegExp,$Argv)?$Argv:False;
}
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/931549.htmlTechArticleA summary of test function examples commonly used when php user registration, php user registration This article summarizes the commonly used test functions when php user registration Test function. Share it with everyone for your reference. The specific analysis is as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template