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 );}}