夜间福利网站,免费动漫av,一级做a爰片久久毛片免费陪,夜夜骑首页,黄色毛片视频,插插插操操操,综合av色

php常用的驗(yàn)證類以及正則實(shí)例

時(shí)間:2025-11-08 20:42:35 php語言

php常用的驗(yàn)證類以及正則實(shí)例

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

  include "ValidateParameterConfig.php";

  class Validation

  {

  private static function getRexp($rexp)

  {

  $_rexp = array (

  'letter_number'=>'/^[0-9A-Za-z]+$/',/pic/p>

  'account'=>'/^[0-9A-Za-z_]+$/',/pic/p>

  'ids'=>'/^[0-9]+(,[0-9]+)*$/',/pic/p>

  'number'=>'/^[0-9]+$/',/pic/p>

  'personal_card'=>'/^[0-9A-Za-z]+$/',/pic/p>

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

  '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))$/'/pic/p>

  );

  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)

  {

  /pic/p>

  $_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;

  }

  }

  }

  使用例子:

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

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

  /pic/p>

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

  if ($_msg !== null) {

  return $_msg . ' is invalid parameter';

  }

【php常用的驗(yàn)證類以及正則實(shí)例】相關(guān)文章:

用php常用表單驗(yàn)證的正則表達(dá)式02-27

php正則去掉php注釋09-25

PHP內(nèi)存緩存Memcached類實(shí)例12-08

PHP常用的正則表達(dá)式11-06

PHP常用正則表達(dá)式02-15

PHP中常用的實(shí)例介紹11-18

PHP知識:PHP常用正則表達(dá)式大全03-16

PHP中使用crypt()實(shí)現(xiàn)用戶身份驗(yàn)證的實(shí)例08-17

PHP實(shí)現(xiàn)RSA加密類的實(shí)例解析09-17