奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

php常用的驗證類以及正則實例

時間:2024-08-27 07:23:08 php語言 我要投稿
  • 相關推薦

php常用的驗證類以及正則實例

  導語:php常用的驗證類及正則,你知道多少呢?以下的是百分網(wǎng)小編為大家搜集的php常用驗證類及正則,希望對你有所幫助。

  include "ValidateParameterConfig.php";

  class Validation

  {

  private static function getRexp($rexp)

  {

  $_rexp = array (

  'letter_number'=>'/^[0-9A-Za-z]+$/',//只有字母數(shù)字包括大小寫

  'account'=>'/^[0-9A-Za-z_]+$/',//只有字母數(shù)字下劃線包括大小寫

  'ids'=>'/^[0-9]+(,[0-9]+)*$/',//驗證多個id以','分割的類型 例如'1,2,3,4,5'

  'number'=>'/^[0-9]+$/',//只可以使數(shù)字

  'personal_card'=>'/^[0-9A-Za-z]+$/',//身份證

  'email'=>'/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/',//郵箱

  '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]|1d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/'//日期,包含了閏年

  );

  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['allow_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或allow_exist不存在表示該參數(shù)必傳

  $_config = array(

  'test'=>array(

  'letter_number'=>array('rexp'=>'letter_number', 'allow_exist'=>true),

  'number'=>array('rexp'=>'number', 'min_length'=>1'allow_exist'=>false),

  'account'=>array('rexp'=>'account', 'max_length'=>20),

  )

  );

  if (isset($_config[$key])) {

  return $_config[$key];

  } else {

  return $config_not_defind;

  }

  }

  }

  使用例子:

  從應用端發(fā)過來的參數(shù)為

  $arr = array('letter_number'=>'abc123', 'account'=>'acb1234_');

  //參數(shù)驗證

  $_msg = Validation::validate($arr, 'test');

  if ($_msg !== null) {

  return $_msg . ' is invalid parameter';

  }

【php常用的驗證類以及正則實例】相關文章:

php正則去掉php注釋07-30

php學習筆記:類的聲明與對象實例化05-14

PHP socket的配置及實例10-16

php查詢mysql的實例09-09

php編寫的一個E-mail驗證類08-26

php漢字正則表達式06-03

php中fsockopen用法實例06-20

php簡單偽靜態(tài)實例09-16

php如何實現(xiàn)驗證碼06-13

PHP處理密碼的幾種方式實例09-27

主站蜘蛛池模板: 丘北县| 七台河市| 沅陵县| 双柏县| 呼图壁县| 温宿县| 固镇县| 易门县| 汶上县| 南江县| 杂多县| 阿拉善右旗| 公主岭市| 始兴县| 文山县| 白沙| 阳高县| 台州市| 兴国县| 新田县| 兴文县| 色达县| 万山特区| 新宾| 务川| 香港 | 乡宁县| 胶南市| 商丘市| 从化市| 清远市| 建瓯市| 仪征市| 和林格尔县| 湛江市| 依兰县| 宁强县| 楚雄市| 临朐县| 太湖县| 高碑店市|