php验证日常格式_邮箱验证_手机验证_身份正验证_网址验证_时间验证
<?php
/*
* Author : lemonice
*
* Email:chengciming@126.com
*
* 时间:2011-11
*
* 说明:验证日常格式(Email等)
*
*/
/**
* 验证输入的邮件地址是否合法
*
* @access public
* @param string $user_email 需要验证的邮件地址
*
* @return bool
*/
function is_email($user_email){
$chars = "/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/i";
if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false){
if (preg_match($chars, $user_email)){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
/**
* 验证输入的手机号码
*
* @access public
* @param string $user_mobile 需要验证的手机号码
*
* @return bool
*/
function is_mobile($user_mobile){
$chars = "/^(((d{2,3}))|(d{3}-))?1(3|5|8|9)d{9}$/";
if (preg_match($chars, $user_mobile)){
return true;
}else{
return false;
}
}
/**
* 验证输入的电话号码
*
* @access public
* @param string $user_phone 需要验证的电话号码
*
* @return bool
*/
function is_phone($user_phone){
$chars = "/^(((d{2,3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9]d{6,7}(-d{1,4})?$/";
if (preg_match($chars, $user_phone)){
return true;
}else{
return false;
}
}
/**
* 验证输入的网址
*
* @access public
* @param string $user_url 需要验证的网址
*
* @return bool
*/
function is_url($user_url){
$chars = "/((^http)|(^https)|(^ftp))://(S)+.(w)+/";
if (preg_match($chars, $user_url)){
return true;
}else{
return false;
}
}
/**
* 验证输入的字符串是否带有特殊符号
*
* @access public
* @param string $user_safe 需要验证的字符串
*
* @return bool
*/
function is_safe($user_safe){
$chars = "/^(([A-Z]*|[a-z]*|d*|[-_~!@#$%^&*.()[]{}<>?\/'"]*)|.{0,5})$|s/";
if (!preg_match($chars, $user_safe)){
return true; //找不到特殊字符则返回true
}else{
return false;
}
}
/**
* 检查是否为一个合法的时间格式
*
* @access public
* @param string $time 格式:2011-11-16 15:54:13
* @return void
*/
function is_time($time){
$pattern = '/[d]{4}-[d]{1,2}-[d]{1,2}s[d]{1,2}:[d]{1,2}:[d]{1,2}/';
return preg_match($pattern, $time);
}
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号