- /**
- * Verification class
- *
- * @ Lastmodify 5-5-16
- * @ Author jy625
- */
- Class VerifyAction {
- /**
- * Whether it is null
- */
- Public static function isEmpty ($ str ){
- $ Str = trim ($ str );
- Return! Empty ($ str )? True: false;
- }
- /**
- * Digit verification
- * Param: $ flag: whether the int is an integer or the float is a floating point.
- */
- Public static function isNum ($ str, $ flag = 'float '){
- If (! Self: isEmpty ($ str) return false;
- If (strtolower ($ flag) = 'int '){
- Return (string) (int) $ str ==( string) $ str )? True: false;
- } Else {
- Return (string) (float) $ str ==( string) $ str )? True: false;
- }
- }
- /**
- * Name matching, such as user name and directory name
- * @ Param: string $ str string to be matched
- * @ Param: $ whether chinese is supported. it is supported by default. if the file name is matched, disable this option (false)
- * @ Param: $ charset encoding (UTF-8 by default, supports gb2312)
- */
- Public static function isName ($ str, $ chinese = true, $ charset = 'utf-8 '){
- If (! Self: isEmpty ($ str) return false;
- If ($ chinese ){
- $ Match = (strtolower ($ charset) = 'gb2312 ')? "/^ [". Chr (0xa1 ). "-". chr (0xff ). "A-Za-z0-9 _-] + $/": "/^ [x {4e00}-x {9fa5} A-Za-z0-9 _] + $/u ";
- } Else {
- $ Match = '/^ [A-za-z0-9 _-] + $ /';
- }
- Return preg_match ($ match, $ str )? True: false;
- }
- /**
- * Email verification
- */
- Public static function isEmail ($ str ){
- If (! Self: isEmpty ($ str) return false;
- Return preg_match ("/([a-z0-9] * [-_ \.]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [\.] [a-z] {2, 3} ([\.] [a-z] {2 })? /I ", $ str )? True: false;
- }
- // Mobile phone number verification
- Public static function isMobile ($ str ){
- $ Exp = "/^ 13 [0-9] Beckham [0-9] {8} $ | 15 [012356789] Beckham [0-9] {8} $ | 18 [012356789] Beckham [0-9] {8 }$ | 14 [57] Beckham [0-9] $ /";
- If (preg_match ($ exp, $ str )){
- Return true;
- } Else {
- Return false;
- }
- }
- /**
- * URL verification, in pure URL format, does not support IP Address Verification
- */
- Public static function isUrl ($ str ){
- If (! Self: isEmpty ($ str) return false;
- Return preg_match ('# (http | https | ftp | ftps): // ([w-] +.) + [w-] + (/[w -./? % & =] *)? # I ', $ str )? True: false;
- }
- /**
- * Verify Chinese characters
- * @ Param: string $ str string to be matched
- * @ Param: $ charset encoding (UTF-8 by default, supports gb2312)
- */
- Public static function isChinese ($ str, $ charset = 'utf-8 '){
- If (! Self: isEmpty ($ str) return false;
- $ Match = (strtolower ($ charset) = 'gb2312 ')? "/^ [". Chr (0xa1). "-". chr (0xff). "] + $ /"
- : "/^ [X {4e00}-x {9fa5}] + $/u ";
- Return preg_match ($ match, $ str )? True: false;
- }
- /**
- * UTF-8 verification
- */
- Public static function isUtf8 ($ str ){
- If (! Self: isEmpty ($ str) return false;
- Return (preg_match ("/^ ([". chr (1, 228 ). "-". chr (1, 233 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham) Beckham/", $ word)
- = True | preg_match ("/([". chr (1, 228 ). "-". chr (1, 233 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham) Beckham $/", $ word)
- = True | preg_match ("/([". chr (1, 228 ). "-". chr (1, 233 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham [". chr (1, 128 ). "-". chr (1, 191 ). "] Beckham) {2,}/", $ word)
- = True )? True: false;
- }
- /**
- * Verification length
- * @ Param: string $ str
- * @ Param: int $ type (method, default value: min <= $ str <= max)
- * @ Param: int $ min, minimum value; $ max, maximum value;
- * @ Param: string $ charset character
- */
- Public static function length ($ str, $ type = 3, $ min = 0, $ max = 0, $ charset = 'utf-8 '){
- If (! Self: isEmpty ($ str) return false;
- $ Len = mb_strlen ($ str, $ charset );
- Switch ($ type ){
- Case 1: // only match the minimum value
- Return ($ len >=$ min )? True: false;
- Break;
- Case 2: // only match the maximum value
- Return ($ max >=$ len )? True: false;
- Break;
- Default: // min <= $ str <= max
- Return ($ min <= $ len) & ($ len <= $ max ))? True: false;
- }
- }
- /**
- * Verify the password
- * @ Param string $ value
- * @ Param int $ length
- * @ Return boolean
- */
- Public static function isPWD ($ value, $ minLen = 6, $ maxLen = 16 ){
- $ Match = '/^ [\\~! @ # $ % ^ & * ()-_ = + | {}
- ,.? \/:; \ '\ "\ D \ w] {'. $ minLen. ','. $ maxLen. '} $ /';
- $ V = trim ($ value );
- If (empty ($ v ))
- Return false;
- Return preg_match ($ match, $ v );
- }
- /**
- * Verify the user name
- * @ Param string $ value
- * @ Param int $ length
- * @ Return boolean
- */
- Public static function isNames ($ value, $ minLen = 2, $ maxLen = 16, $ charset = 'all '){
- If (empty ($ value ))
- Return false;
- Switch ($ charset ){
- Case 'en': $ match = '/^ [_ \ w \ d] {'. $ minLen. ','. $ maxLen. '} $/iu ';
- Break;
- Case 'cn': $ match = '/^ [_ \ x {4e00}-\ x {9fa5} \ d] {'. $ minLen. ','. $ maxLen. '} $/iu ';
- Break;
- Default: $ match = '/^ [_ \ w \ d \ x {4e00}-\ x {9fa5}] {'. $ minLen. ','. $ maxLen. '} $/iu ';
- }
- Return preg_match ($ match, $ value );
- }
- /**
- * Verify email
- * @ Param string $ value
- */
- Public static function checkZip ($ str ){
- If (strlen ($ str )! = 6 ){
- Return false;
- }
- If (substr ($ str, 0, 1) = 0 ){
- Return false;
- }
- Return true;
- }
- /**
- * Matching date
- * @ Param string $ value
- */
- Public static function checkDate ($ str ){
- $ DateArr = explode ("-", $ str );
- If (is_numeric ($ dateArr [0]) & is_numeric ($ dateArr [1]) & is_numeric ($ dateArr [2]) {
- If ($ dateArr [0]> = 1000 & $ timeArr [0] <= 10000) & ($ dateArr [1]> = 0 & $ dateArr [1] <= 12) & ($ dateArr [2]> = 0 & $ dateArr [2] <= 31 ))
- Return true;
- Else
- Return false;
- }
- Return false;
- }
- /**
- * Matching time
- * @ Param string $ value
- */
- Public static function checkTime ($ str ){
- $ TimeArr = explode (":", $ str );
- If (is_numeric ($ timeArr [0]) & is_numeric ($ timeArr [1]) & is_numeric ($ timeArr [2]) {
- If ($ timeArr [0]> = 0 & $ timeArr [0] <= 23) & ($ timeArr [1]> = 0 & $ timeArr [1] <= 59) & ($ timeArr [2]> = 0 & $ timeArr [2] <= 59 ))
- Return true;
- Else
- Return false;
- }
- Return false;
- }
- }
|