<无详细内容>
- /**
- * Page function: Common form verification classes
- * Prepared by: phper
- * Creation Time: 2011-4-11
- */
- Class validate {
- Public static function isEmail ($ str ){
- Return is_string ($ str) & preg_match ('/^ [_\. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + \.) + [a-z] {2, 4} $/', $ str );
- }
- Public static function isUrl ($ str ){
- Return is_string ($ str) & preg_match ("/^ http: \ // [A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \': +!] * ([^ <> \ "\"]) * $/", $ Str );
- }
- Public static function isPhone ($ str, $ type ){
- $ Preg_array_pho = array (
- 'Cn' => '/^ (\ d {3} \) | (\ d {3 }\-))? (\ (0 \ d {2, 3} \) | 0 \ d {2, 3 }-)? [1-9] \ d {6, 7} $ /',
- 'Tw '=>''
- );
- If (in_array ($ type, array_keys ($ pre_array_pho ))){
- Return preg_match ($ pre_array_pho [$ type], $ str );
- } Else {
- Die ($ type. '-phone number is undefined ');
- }
- }
- Public static function isText ($ str, $ type, $ min_lenth = 1, $ max_lenth = ''){
- $ Preg_array_text = array (
- 'Ch' => "/^ ([\ x81-\ xfe] [\ x40-\ xfe]) {". $ min_lenth. ",". $ max_lenth. "} $ /",
- 'Num' => "/^ [0-9] {". $ min_lenth. ",". $ max_lenth. "} $/I ",
- );
- If (in_array ($ type, array_keys ($ preg_array_text ))){
- Return is_string ($ preg_array_text) & preg_match ($ preg_array_text [$ type], $ str );
- } Else {
- Die ($ type. '-text is undefined ');
- }
- }
- Public static function isIp ($ ip ){
- Return preg_match ("/^ ([1-9] | [1-9] [0-9] | 1 [0-9] [0-9] | 2 [0-9- 4] [0-9] | 25 [0-5]) ". "(\. ([0-9] | [1-9] [0-9] | 1 [0-9] [0-9] | 2 [0-4] [0-9] | 25 [0-5]) {3} $/", $ ip );
- }
- Public static function isDate ($ var ){
- Return preg_match ("/([0-9] {4})-([0-9] {1, 2})-([0-9] {1, 2 })/", $ var );
- }
- Public static function isColor ($ var ){
- Return preg_match ("/^ #? ([A-f] | [A-F] | [0-9]) {3} ([a-f] | [A-F] | [0-9]) {3 })? $/", $ Var );
- }
- Public static function isUserName ($ var ){
- Return preg_match ("/^ [a-zA-Z0-9 _ \. \-] {} $/", $ var );
- }
- Public static function isPic ($ var ){
- Return preg_match ("/^ [a-zA-Z0-9 \-\.] + \. (jpg | jpeg | gif | png) $/", $ var );
- }
- }
- ?>
|