表单验证一直很繁琐,特别是大点的表单,如果每个input都去单独写验证简直要写死人,最近写了一小段js统一的验证表单内容是否正确。
使用这段代码就不再需要对每个input写格式判断,只需要将正确格式的正则表达式写在datatype里就可以了,提交表单按钮也只需要绑定checkForm函数就可以了。
大家有什么建议可以评论一下
<input type="text" datatype=“正则”/>
//表单验证
//点击下一步事件
function checkForm(form){
var success = true;
$("."+form+" input").each(function(){