Php-encapsulated Form Verification class complete instance, php-encapsulated form instance

Source: Internet
Author: User

Php-encapsulated Form Verification class complete instance, php-encapsulated form instance

This example describes the Form Verification class encapsulated by php. We will share this with you for your reference. The details are as follows:

<? Php // encapsulate a Form Verification class // Chinese Character verification, email verification, phone number, mobile phone number, QQ, ID card, (composed of letters, numbers, underscores, cannot start with a number) header ('content-type: text/html; charset = UTF-8 '); class Form {/* // Chinese verification method // parameter: $ str, $ num1, $ num2 // return value: Number of successful matches returned */public function checkChina ($ str, $ num1, $ num2 = '') {// regular $ reg = '/^ [\ x {4e00}-\ x {9fa5}] {'. $ num1 .','. $ num2 .'}'. '$/U'; return preg_match ($ reg, $ str);}/* // email verification // parameter: $ email // return value: number of matched times */public function checkEmail ($ email) {// regular $ reg = '/^ \ w + @ \ w + [.] com | cn | net $/'; return preg_match ($ reg, $ email);}/* // verify the ID card // parameter $ card // return value: number of matched times */public function checkCard ($ card) {// regular $ reg = '/^ (\ d {18} | \ d {17} x) $/'; return preg_match ($ reg, $ card);}/* // The input content must consist of digits, letters, and underscores. It cannot start with a number, number of digits limit // parameter: $ str, $ num1, $ num2 // return value: the number of times a match is returned */public function checkStr ($ str, $ num1, $ num2) {// regular $ reg = '/^ [a-zA-Z _] \ w {'. ($ num1-1 ). ','. ($ num2-1 ). '} $/'; return preg_match ($ reg, $ str );}}

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.