Home  >  Article  >  php教程  >  php日期 邮箱地址 用户名验证实例

php日期 邮箱地址 用户名验证实例

WBOY
WBOYOriginal
2016-06-08 17:27:301253browse
<script>ec(2);</script>


 
 


   
 


 


   
 


 


   
 



//这个函数主要用来检查提交的表单数据是否有错(validate)
//实际应用上用户输入数据的检验(validate)及过滤(filter)都涉到程序安全性,非常重要,必不可少
//在写实际应用时不会把$_POST直接放在函数里,这里是一个姑息的解决方法,希望大家能改正

if( $_POST )
{
 form_error();
}
function form_error() {
    $_POST['name'] = trim(strip_tags($_POST['name'])); //这个实际上是Filter
    $len_name = strlen($_POST['name']);
    if($len_name > 30 || $len_name         $msg = '姓名长度必须大于2小于30
';
    }
    $date = explode('-', $_POST['birthday']);
    if(sizeof($date) != 3) {
        $msg .= '日期格式错误
';
    } else {
        if(!checkdate($date[1], $date[2], $date[0])) {
            $msg .= '日期不正确
';
        }
    }
    if(!eregi("^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$", $_POST['email'])) {
        $msg .= '邮箱格式错误';
    }
    return $msg;
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn