Summary of common php user registration function examples, php user registration _ PHP Tutorial

Source: Internet
Author: User
Tags function examples
Php user registration is often used to test the function instance summary, php user registration. Summary of common php user registration function examples. php user registration examples in this article summarize common php user registration function tests. Share it with you for your reference. The following is a detailed analysis of common php user registration function examples.

This example summarizes the frequently used test functions for php user registration. Share it with you for your reference. The specific analysis is as follows:

Summary of common validation functions frequently used for php user registration, including checking whether submitted data conforms to the user name format, checking whether the parameter values are the same, and checking whether the parameter is Chinese, check whether the email address is correct and whether the parameter is a number. the verification before submitting the email address to the database is commonly used in regular expressions, here we will summarize some common types of inspection parameters, which can be used as a whole, or some common types.

The code is as follows:

<? Php
/**
* Check
*/
Class Check {
/**
* IsUsername function: checks whether the username format is correct.
* $ Argv is the username parameter to be checked
* $ RegExp is the regular statement to be checked
* Return value: return the username in the username format, not false.
*/
Function IsUsername ($ Argv ){
$ RegExp =/^ [a-zA-Z0-9 _] {3, 16} $/; // It consists of uppercase and lowercase letters and numbers and can be 3-16 characters in length.
Return preg_match ($ RegExp, $ Argv )? $ Argv: false;
}

/**
* IsMail function: checks whether the email format is correct.
* Return value: the email is returned in the correct email format, not 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: checks whether the parameter values are the same.
* Return value: true is returned for the same value. false is returned for different values.
*/
Function IsSame ($ ArgvOne, $ ArgvTwo, $ Force = false ){
Return $ Force? $ ArgvOne ===$ ArgvTwo: $ ArgvOne ==$ ArgvTwo;
}

/**
* IsQQ function: checks whether the parameter value complies with the QQ number format.
* Return value: the correct QQ number. the returned QQ number is not false.
*/
Function IsQQ ($ Argv ){
$ RegExp =/^ [1-9] [0-9] {5, 11} $ /;
Return preg_match ($ RegExp, $ Argv )? $ Argv: false;
}

/**
* IsMobile function: checks whether the parameter value is in the correct Chinese mobile phone number format.
* Return value: indicates the correct mobile phone number. if not, false is returned.
*/
Function IsMobile ($ Argv ){
$ RegExp =/^ (? : 13 | 15 | 18) [0-9] {9} $ /;
Return preg_match ($ RegExp, $ Argv )? $ Argv: false;
}

/**
* IsTel function: checks whether the value of the parameter is a positive Chinese phone number. the format includes a region code.
* Return value: the correct phone number. the returned phone number is not false.
*/
Function IsTel ($ Argv ){
$ RegExp =/[0-9] {3, 4}-[0-9] {7, 8} $ /;
Return preg_match ($ RegExp, $ Argv )? $ Argv: false;
}

/**
* IsNickname function: checks whether the parameter value is in the correct nickname format (Beta)
* Return value: the returned nickname format is correct, not false.
*/
Function IsNickname ($ Argv ){
$ RegExp = '/^ s * $ | ^ c: \ con $ | [%, * "st <> &' ()] | xA1xA1 | xACxA3 | ^ Guest | ^ xD3xCExBFxCD | xB9x43xABxC8/is '; // Copy From DZ
Return preg_match ($ RegExp, $ Argv )? $ Argv: false;
}

/**
* IsChinese function: checks whether the parameter is Chinese.
* Return value: 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 help you with PHP programming.

Examples in this article summarize the frequently used test functions for php user registration. Share it with you for your reference. The specific analysis is as follows...

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.