zip/邮政编码数字验证检查
我需要将要验证的邮政编码字段设置为至少包含一个数字,但似乎我缺少一些东西,因为它不起作用:
if( isset( $required_fields['zip'] )) {
echo '
if( =(/^(?=.*[0-9])(?=.*[a-zA-Z])+$/.test(form.zip.value))) {
alert( \'Please enter a valid Zip Code\');
return false;
}';
}
有人可以告诉我出了什么问题吗?
提前致谢
I need to set the postcode field to be validated to have at least one number in it but seems like im missing something becuase it is not working:
if( isset( $required_fields['zip'] )) {
echo '
if( =(/^(?=.*[0-9])(?=.*[a-zA-Z])+$/.test(form.zip.value))) {
alert( \'Please enter a valid Zip Code\');
return false;
}';
}
can someone tell me what is wrong please?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要的模式是这样的:
^(?=.*[0-9])([\w]+)$
您在 [a-zA-Z] 上使用正向前瞻而不是实际的字符匹配,并且前瞻仅匹配位置,而不匹配字符。当然,模式 [\w] 可以替换为一些更具限制性的模式。
The pattern you need is this:
^(?=.*[0-9])([\w]+)$
You were using positive look-ahead on [a-zA-Z] instead of actual character matching, and the look-aheads match only a position, not characters. Of course, the pattern [\w] can be replaced with some more restrictive pattern.