首页 > 代码库 > Javascript基本表单验证

Javascript基本表单验证

<script type="text/javascript">    function checkForm(form) {        if (form.name.value =http://www.mamicode.com/="") {            alert("姓名不能为空!");            return false;        }        if (form.password.value.length < 6||form.password.value.length > 13) {            alert("密码长度应在6-13之间!");            return false;        }        if (form.age.value<0||form.age.value>120) {            alert("请输入正确的年龄!");            return false;        }                if (form.email.value.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)==null) {            alert("请输入正确的邮箱!");            return false;        }            }</script>

form表单<form action="regist.do" method="post" onsubmit="return checkForm(this)" name="form">

中input标签里面name对应(name password age(int) email)即可    比如:<input type="text" class="inputgri" name="email" />

Javascript基本表单验证