搜索热词
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:
/**
* 表单验证
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function validatePost( $regs,$ferrors )
{
$errors = array();
foreach( $regs as $k => $v )
{
if( ! preg_match( $v,$_POST[$k] ) )
{
$errors[$k] = $ferrors[$k];
}
}
return $errors;
}
// has the post been submitted?
if( count( $_POST ) )
{
// yes it has been submitted so lets validate
$regs['last_name'] = "/^[[:alpha:]\ -]+$/"; // require a alpha
$regs['first_name'] = "/^[[:alpha:]\ -]+$/"; // require a alpha
$regs['email'] = "/^..*\@..*$/"; // VERY simple email check
// Use google to find better
// Ok here are the error message to display when it is bad
$ferrors['last_name'] = "Last name required";
$ferrors['first_name'] = "First name required";
$ferrors['email'] = "Email name required";
$errors = validatePost( $regs,$ferrors );
// Do we have errors?
if( count( $errors ) == 0 )
{
// WE HAVE NO ERRORS DO SOMETHING
// PUT IT INTO THE DATABASE,EMAIL,BOUNCE THE USER
// TO A THANK YOU PAGE,ETC...
}
}
?> 经测试代码如下:
Last Name
= $errors['last_name'] ?>
First Name
= $errors['first_name'] ?>
= $errors['email'] ?>
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。