Regular expressions are constantly updated when they encounter new
Include "<span style=" Font-family:consolas, ' Courier New ', Courier, mono, serif; line-height:18px; " >ValidateParameterConfig.php</span> ";
Class Validation {private static function Getrexp ($rexp) {$_rexp = array (' letter_number ' = '/^[0-9a-za-z]+$/',// Only alphanumeric include case ' account ' = '/^[0-9a-za-z_]+$/',//only alphanumeric underscore including case ' ids ' = '/^[0-9]+ (\,[0-9]+) *$/',//Verify multiple IDs with ', ' The type of segmentation such as ' 1,2,3,4,5 ' ' number ' = '/^[0-9]+$/',//can only make the numbers ' Personal_card ' and '/^[0-9a-za-z]+$/',//ID card ' email ' = '/ ^ ([a-za-z0-9_\.\-]) +\@ ([[a-za-z0-9\-]) +\.) + ([a-za-z0-9]{2,4}) +$/',//mailbox ' date ' = '/^ ((((19|20) \d{2})-(0? ( 1| [3-9]) | 1[012])-(0?[ 1-9]| [12]\d|30)] | (((19|20) \d{2})-(0?[ 13578]|1[02])-31) | ((19|20) \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((19|20) ([13579][26]|[ 2468][048]|0[48]) | (2000)) -0?2-29)) $/'//date, including leap year, if (Isset ($_rexp[$rexp]) {return $_rexp[$rexp];} else {return $rexp _not_defind;}} public static function Validate ($data, $config) {$_config = Validateparameterconfig::getconfig ($config); $k = self:: Allowexist ($data, $_config); if ($k!== null) {return $k;} foreach ($_config as $k = = $c) {if (Isset ($data [$k])) {if (Isset ($c [' Rexp '])) {if (Self::vrexp ($data [$k], $c [' Rexp '])= = = False) {return $k;}} if (Isset ($c [' length '])) {if (Self::vlength ($data [$k], $c [' length ']) {return $k;}} if (Isset ($c [' min_length '])) {if (!self::vminlength ($data [$k], $c [' min_length ']) {return $k;}} if (Isset ($c [' max_length '])) {if (!self::vmaxlength ($data [$k], $c [' max_length ']) {return $k;}}} return null;} private static function Allowexist ($data, $config) {foreach ($config as $k + $v) {if (!isset ($v [' allow_exist ']) | | $v [' A Llow_exist '] = = True) {if (!isset ($data [$k]) {return $k;}}} return null;} public static function Vrexp ($data, $rexp) {$_rexp = Self::getrexp ($rexp), if (Preg_match ($_rexp, $data) = = False) {return false;} return true;} public static function Vlength ($data, $l) {if (strlen (Trim ($data)) = = $l) {return false;} return true;} public static function Vminlength ($data, $l) {if (strlen (Trim ($data)) < $l) {return false;} return true;} public static function Vmaxlength ($data, $l) {if (strlen (Trim ($data)) > $l) {return false;} return true;} public static function Vletternumber ($data) {if (Preg_match (Self::getrexp (' Letter_number '), $data) = = False) {return false;} return true;} public static function Vletternumber_ ($data) {if (Preg_match (Self::getrexp (' Letter_number_ '), $data) = = False) {return false;} return true;} public static function Vnumber ($data) {if (Preg_match (Self::getrexp (' number '), $data) = = False) {return false;} return true;} public static function Vemail ($data) {if (Preg_match (self::getrexp (' email '), $data) = = False) {return false;} return true;}
Class Validateparameterconfig {public static function GetConfig ($key) {//' allow_exist ' =>true or Allow_ exist does not exist to indicate that the parameter must be $_config = Array (' Test ' =>array (' Letter_number ' =>array (' rexp ' = ' letter_number ', ' Allow_ Exist ' =>true), ' Number ' =>array (' rexp ' = ' number ', ' min_length ' =>1<span style= ' font-family:arial, Helvetica, Sans-serif; " > ' allow_exist ' =>false</span>), ' Account ' =>array (' rexp ' = ' account ', ' max_length ' =>20),)); if ( Isset ($_config[$key]) {return $_config[$key];} else {return $config _not_defind;}}
Examples of Use:
The parameters sent from the application end are
$arr = Array (' letter_number ' = ' abc123 ', ' account ' = ' acb1234_ ');//parameter Validation $_msg = Validation::validate ($arr, ' test ' if ($_msg!== null) {return $_msg. ' is invalid parameter ';}