非常简单的php验证.

WBOY
Release: 2016-06-23 14:07:49
Original
766 people have browsed it

请大神给段代码吧,我知道很简单,可是我试验很多方法,不是不跳转就是原地不动。怎么也搞不出来.
就是实现:输入框写邮政编码,然后验证如果是5个数字就跳转到下一页,不是5就停留在原页并且在输入框后面添加“邮政编码不对”.
感谢各位大神.


回复讨论(解决方案)

邮政编码是6位数吧?

这是个基础的表单验证,js 就搞定了。何必劳烦 php ?

js正则判断一下就可以了

<script> <br /> function iszipcode(object) <br /> { <br /> var s =document.getElementById(object.id).value; <br /> var pattern =/^[0-9]{6}$/; <br /> if(s!="") <br /> { <br /> if(!pattern.exec(s)) <br /> { <br /> alert('请输入正确的邮政编码'); <br /> object.value=""; <br /> object.focus(); <br /> } <br /> } <br /> } <br /> <br /> </script>

可以自己试着写写哦!

if(ereg('/\d{5}/',$string))echo 'Right';

楼主要的就是这个PHP?

这个用JS判断下就行了,你要求输错了再后面提示信息的话,只能用js最简单了~

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template