PHP matches what type is currently passed in

Source: Internet
Author: User
Tags preg

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.