This article to: The new Too Current network blog
/** * [Is_string_regular_type automatically validates incoming data] * @e-mial [email protected] * @TIME 2017-08-25 * @WEB http://blog.iinu.com. CN * @param [string] $keyword [the range to be retrieved by the passed-in keyword] * @param [string] $string [content that needs to be matched with a regular match] * @return Boolean [return array State] */functionIs_string_regular_type($keyword,$string){$type _array=Array( Mailbox Regular ' Email ' = [ ' Type ' = '/^\w+ ((-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ ((\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/'], User name ' Username ' = [ ' Type ' = '/^\w+ ((-\w+) | ( \.\w+)) *[0-9a-za-z_]/' , ' Number ' = '/^\w+ ((-\w+) | ( \.\w+)) *[0-9a-za-z_]{6,20}/'], Password ' Password ' = [ ' Type ' = '/^[0-9a-za-z_]{6,20}$/'] );$return _str_success=Array( ' Email ' = [' Type '=' Mailbox format is correct '], ' Username ' = [' Type '=' User name format correct ',' Number '=' User name length correct '], ' Password ' = [' Type '=' Password format is correct '] );$return _str_error=Array( ' Email ' = [' Type '=' Mailbox format is not correct '], ' Username ' = [' Type '=' User name format is incorrect ',' Number '=' User name length is incorrect '], ' Password ' = [' Type '=' Password format is incorrect '] ); Used to match whether the key exists Foreach($type _arrayAs$k=$v){$type _array_if[] =$k; } If(In_array($keyword,$type _array_if)){ Foreach($type _array[$keyword] As$k=$v){ Regular histograms$preg _match_chek=Preg_match($type _array[$keyword][$k],$string); } If($preg _match_chek== 1){ Match success ReturnArray(' Status '=$preg _match_chek,' Result '=$return _str_success[$keyword][$k],' Message '=$string); }Else{ Match failed ReturnArray(' Status '=$preg _match_chek,' Result '=$return _str_error[ $keyword ][ $k ], =>1, ' result ' => ' This verification method does not exist ' , ' message ' => $string }} /span>
This article to: The new Too Current network blog
PHP matches what type is currently passed in