The example of this article summarizes the common checking function of PHP user registration. Share to everyone for your reference. The specific analysis is as follows:
PHP user registration commonly used in a number of commonly used test function summary, including the detection of the submission of data is consistent with the user name format, detection parameters are the same value, detection parameters are Chinese, check the address of the mailbox is correct, check whether the parameters are numbers, etc., these submitted to the database before the verification In the regular expression inside is commonly used, here will be some commonly used test parameters of the type to make a summary, you can use the whole, you can pick some commonly used to use.
Copy Code code as follows:
<?php
/**
* Check Detection class
*/
Class check{
/**
* Isusername function: Detects if the user name format is met
* $ARGV is the user name parameter to be detected
* $REGEXP is the regular statement to be detected
* Return value: Returns the username in accordance with username format, not return False
*/
function Isusername ($ARGV) {
$REGEXP =/^[a-za-z0-9_]{3,16}$/; Composed of uppercase and lowercase letters with numbers and length in 3-16 characters straight
Return Preg_match ($REGEXP, $Argv)? $ARGV: false;
}
/**
* Ismail function: Detect if the message format is correct
* Return value: Is the correct message format to return the message, 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: Detect whether the value of the parameter is the same
* Return value: Same return true, not the same return false
*/
function Issame ($ArgvOne, $ArgvTwo, $Force =false) {
Return $Force? $ArgvOne = = $ArgvTwo: $ArgvOne = = $ArgvTwo;
}
/**
* ISQQ function: Detect the value of the parameter is in line with the QQ number format
* Return value: Is the correct QQ number return QQ number, not return false
*/
function isqq ($ARGV) {
$REGEXP =/^[1-9][0-9]{5,11}$/;
Return Preg_match ($REGEXP, $Argv)? $ARGV: false;
}
/**
* IsMobile function: Check whether the value of the parameter is the correct Chinese phone number format
* Return value: is the correct cell phone number return 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 positive the China phone number format includes the area code
* Return value: Is the correct phone number return phone number, not return false
*/
function Istel ($ARGV) {
$REGEXP =/[0-9]{3,4}-[0-9]{7,8}$/;
Return Preg_match ($REGEXP, $Argv)? $ARGV: false;
}
/**
* Isnickname function: Detect whether the value of the parameter is the correct nickname format (Beta)
* Return value: is the correct nickname format to return the nickname format, not return False
*/
function Isnickname ($ARGV) {
$REGEXP = '/^s*$|^c:\con\con$| [%,* "st<>& ' ()]|xa1xa1|xacxa3|^guest|^xd3xcexbfxcd|xb9x43xabxc8/is '"; Copy from DZ
Return Preg_match ($REGEXP, $Argv)? $ARGV: false;
}
/**
* Ischinese function: Check whether the parameter is Chinese
* Return value: Is the return parameter, not return 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 help you with your PHP program design.