PHP 验证表单链接语句问题
我的网站上有一个注册表单,需要在创建帐户之前验证输入。我读到可以轻松禁用 javascript 验证,因此我选择了 php。
我在使用“and”链接不同的验证时遇到问题,不太确定出了什么问题。
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
// Return Error - Invalid Email
$msg = 'Please enter a valid email address.';
} and (!preg_match("/\S+/", $firstname)){
// Return Error - Firstname blank
$msg = 'Please enter your first name.';
} and (!preg_match("/\S+/", $lastname)){
// Return Error - Lastname blank
$msg = 'Please enter your last name.';
}(!preg_match("/.{6,}/", $password)){
// Return Error - password short
$msg = 'The password entered is too short. Please use 6 or more characters.';
}
else{ //submit form
我在验证中是否遗漏了一些有经验的编码员会使用的东西?
希望你能帮助像我这样的新手...
I have a registration form on my website and need to validate the input before creating the account. I have read that javascript validation can be easily disabled so I have opted for php.
I am having issues linking the different validations using 'and' not quite sure what is going wrong.
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
// Return Error - Invalid Email
$msg = 'Please enter a valid email address.';
} and (!preg_match("/\S+/", $firstname)){
// Return Error - Firstname blank
$msg = 'Please enter your first name.';
} and (!preg_match("/\S+/", $lastname)){
// Return Error - Lastname blank
$msg = 'Please enter your last name.';
}(!preg_match("/.{6,}/", $password)){
// Return Error - password short
$msg = 'The password entered is too short. Please use 6 or more characters.';
}
else{ //submit form
Is there anything I am missing from the validation that a more experienced coder would use?
Hope you can help a newbie like me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有检查您的正则表达式,但这里是您的代码的重新定义版本:
这是一种非常简单的做事方式,但我建议下次学习一些验证技术注册表单的教程。
这里有一些很好的教程:
http://www.smashingmagazine。 com/2009/07/07/web-form-validation-best-practices-and-tutorials/
视频第 1 部分:
http://www.youtube.com/watch?v=t8ehovDeMuU
视频第 2 部分:
http://www.youtube.com/watch?v=FlwlpRQo6II
I didn't check your Regular expressions, but here is a redefined version of your code:
This is a very simple way of doing things, but I recommend taking a few tutorials of validating techniques register forms next time.
Here are a few good tutorials:
http://www.smashingmagazine.com/2009/07/07/web-form-validation-best-practices-and-tutorials/
Video part 1:
http://www.youtube.com/watch?v=t8ehovDeMuU
Video part 2:
http://www.youtube.com/watch?v=FlwlpRQo6II