时间:2021-07-01 10:21:17 帮助过:5人阅读
include("check.php");
$check = new VerifyAction();
if(?){
echo '提交成功!';
}else{
echo '填写不对 重填写';
}
验证类 check.php
= $min) ? true : false;
break;
case 2: //只匹配最大值
return ($max >= $len) ? true : false;
break;
default: //min <= $str <= max
return (($min <= $len) && ($len <= $max)) ? true : false;
}
}
/**
* 验证密码
* @param string $value
* @param int $length
* @return boolean
*/
public static function isPWD($value,$minLen=6,$maxLen=16){
$match='/^[\\~!@#$%^&*()-_=+|{}\[\],.?\/:;\'\"\d\w]{'.$minLen.','.$maxLen.'}$/';
$v = trim($value);
if(empty($v))
return false;
return preg_match($match,$v);
}
/**
* 验证用户名
* @param string $value
* @param int $length
* @return boolean
*/
public static function isNames($value, $minLen=2, $maxLen=16, $charset='ALL'){
if(empty($value))
return false;
switch($charset){
case 'EN': $match = '/^[_\w\d]{'.$minLen.','.$maxLen.'}$/iu';
break;
case 'CN':$match = '/^[_\x{4e00}-\x{9fa5}\d]{'.$minLen.','.$maxLen.'}$/iu';
break;
default:$match = '/^[_\w\d\x{4e00}-\x{9fa5}]{'.$minLen.','.$maxLen.'}$/iu';
}
return preg_match($match,$value);
}
/**
* 验证邮箱
* @param string $value
*/
public static function checkZip($str){
if(strlen($str)!=6){
return false;
}
if(substr($str,0,1)==0){
return false;
}
return true;
}
/**
* 匹配日期
* @param string $value
*/
public static function checkDate($str){
$dateArr = explode("-", $str);
if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) {
if (($dateArr[0] >= 1000 && $timeArr[0] <= 10000) && ($dateArr[1] >= 0 && $dateArr[1] <= 12) && ($dateArr[2] >= 0 && $dateArr[2] <= 31))
return true;
else
return false;
}
return false;
}
/**
* 匹配时间
* @param string $value
*/
public static function checkTime($str){
$timeArr = explode(":", $str);
if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) {
if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59))
return true;
else
return false;
}
return false;
}
}
比如我写好的POST提交例子,验证邮箱和值是否未空?
include("check.php");
$check = new VerifyAction();
if(?){
echo '提交成功!';
}else{
echo '填写不对 重填写';
}
验证类 check.php
= $min) ? true : false;
break;
case 2: //只匹配最大值
return ($max >= $len) ? true : false;
break;
default: //min <= $str <= max
return (($min <= $len) && ($len <= $max)) ? true : false;
}
}
/**
* 验证密码
* @param string $value
* @param int $length
* @return boolean
*/
public static function isPWD($value,$minLen=6,$maxLen=16){
$match='/^[\\~!@#$%^&*()-_=+|{}\[\],.?\/:;\'\"\d\w]{'.$minLen.','.$maxLen.'}$/';
$v = trim($value);
if(empty($v))
return false;
return preg_match($match,$v);
}
/**
* 验证用户名
* @param string $value
* @param int $length
* @return boolean
*/
public static function isNames($value, $minLen=2, $maxLen=16, $charset='ALL'){
if(empty($value))
return false;
switch($charset){
case 'EN': $match = '/^[_\w\d]{'.$minLen.','.$maxLen.'}$/iu';
break;
case 'CN':$match = '/^[_\x{4e00}-\x{9fa5}\d]{'.$minLen.','.$maxLen.'}$/iu';
break;
default:$match = '/^[_\w\d\x{4e00}-\x{9fa5}]{'.$minLen.','.$maxLen.'}$/iu';
}
return preg_match($match,$value);
}
/**
* 验证邮箱
* @param string $value
*/
public static function checkZip($str){
if(strlen($str)!=6){
return false;
}
if(substr($str,0,1)==0){
return false;
}
return true;
}
/**
* 匹配日期
* @param string $value
*/
public static function checkDate($str){
$dateArr = explode("-", $str);
if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) {
if (($dateArr[0] >= 1000 && $timeArr[0] <= 10000) && ($dateArr[1] >= 0 && $dateArr[1] <= 12) && ($dateArr[2] >= 0 && $dateArr[2] <= 31))
return true;
else
return false;
}
return false;
}
/**
* 匹配时间
* @param string $value
*/
public static function checkTime($str){
$timeArr = explode(":", $str);
if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) {
if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59))
return true;
else
return false;
}
return false;
}
}
include("check.php");
$check = new VerifyAction();
//验证邮箱
$check_email = $check->isEmail($_POST['email']);
if($check_email)
{
//是正确的邮箱
}else{
//邮箱填写有问题...
}
不知道你明白了么?如果不明白 加群讨论下告诉你 群:231566327
include("check.php");
if($_SERVER['REQUEST_METHOD']=='POST'){
if(!VerifyAction::isEmpty($_POST['name'])){
die("用户名不能为空") ;
}elseif(!VerifyAction::isEmail($_POST['email'])){
die( "无效邮箱账号");
}
echo "验证通过";
}