web常用方法总结
2016-04-27 17:25
204 查看
date_default_timezone_set('PRC');
header("Content-Type:text/html;charset=utf-8");
class funs {
校验电话号码,正则
$telephone
电话号码 支持 010-12345678 01012345678两种
$preg1 正则校验1
$preg2 正则校验2
public
static function cktelephone($telephone){
$preg1 =
"/^0[1-9][0-9]{1,2}-[1-9][0-9]{6,7}$/";
$preg2 =
"/^0[1-9][0-9]{1,2}[1-9][0-9]{6,7}$/";
$rt1 = preg_match($preg1,$telephone);
$rt2 = preg_match($preg2,$telephone);
if($rt1||$rt2){
return true;
}
return false;
}
校验手机号码
支持手机类型
13,14,15,18
public
static function ckmobile($mobile){
$preg = "/^1[3|4|5|8][0-9]{9}$/";
if(preg_match($preg,$mobile)){
return true;
}
return false;
}
邮箱正则处理
支持长度最大为4-80
public
static function ckemail($email){
$preg="/^[a-zA-Z1-9_\.-][a-zA-Z0-9_.-]{3,32}@([a-zA-Z0-9_]+\.){1,5}[A-Za-z]{2,4}$/";
if( preg_match($preg,$email)
&& strlen($email)<70
){
return true;
}
return false;
}
密码复杂度校验处理
public
static function ckpwd($password){
$ErrorArr = array(
"请勿使用纯字母",
"请勿使用纯数字",
"请勿使用连续字符",
"请勿使用空格",
"密码长度建议为6-20个字符,支持字母、数字、下划线、点"
);
if(preg_match("/^[a-zA-Z]+$/",$password)){
return $ErrorArr[0];
} else
if(preg_match("/^[0-9]+$/",$password)){
header("Content-Type:text/html;charset=utf-8");
class funs {
校验电话号码,正则
$telephone
电话号码 支持 010-12345678 01012345678两种
$preg1 正则校验1
$preg2 正则校验2
public
static function cktelephone($telephone){
$preg1 =
"/^0[1-9][0-9]{1,2}-[1-9][0-9]{6,7}$/";
$preg2 =
"/^0[1-9][0-9]{1,2}[1-9][0-9]{6,7}$/";
$rt1 = preg_match($preg1,$telephone);
$rt2 = preg_match($preg2,$telephone);
if($rt1||$rt2){
return true;
}
return false;
}
校验手机号码
支持手机类型
13,14,15,18
public
static function ckmobile($mobile){
$preg = "/^1[3|4|5|8][0-9]{9}$/";
if(preg_match($preg,$mobile)){
return true;
}
return false;
}
邮箱正则处理
支持长度最大为4-80
public
static function ckemail($email){
$preg="/^[a-zA-Z1-9_\.-][a-zA-Z0-9_.-]{3,32}@([a-zA-Z0-9_]+\.){1,5}[A-Za-z]{2,4}$/";
if( preg_match($preg,$email)
&& strlen($email)<70
){
return true;
}
return false;
}
密码复杂度校验处理
public
static function ckpwd($password){
$ErrorArr = array(
"请勿使用纯字母",
"请勿使用纯数字",
"请勿使用连续字符",
"请勿使用空格",
"密码长度建议为6-20个字符,支持字母、数字、下划线、点"
);
if(preg_match("/^[a-zA-Z]+$/",$password)){
return $ErrorArr[0];
} else
if(preg_match("/^[0-9]+$/",$password)){
相关文章推荐
- 中英文混合正则
- php接收数据流
- windows下wnmp搭建教程
- memcache 不稳定问题
- 手机正则和邮箱正则
- 基于scikit-learn(sklearn)做分类--3.优化--保存模型
- 值传递和值引用却别以及测试用例
- php程序员必知的基础~个人总结欢迎…
- 折半插入排序
- php调试工具之firephp
- selenium学习笔记(selenium IDE下载安装)
- Kafka学习(五):Kafka的消费编程模型
- ORA-01843: not a valid month
- ThinkPHP无法add保存数据
- Json-lib
- IntelliJ IDEA 使用svn时遇到的问题总结
- 自定义UITabbarItem的title字体颜色
- sed交换任意两行
- sed交换任意两行
- Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist