Jquery怎么循环遍历每个input框内容不能为空,并且正则验证必须为2-10个汉字,且给出对应的错误提示?
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"></style> <script type="text/javascript" src="jquery-3.0.0.js"></script> </head> <body> <div> 城市1:<input type="text" name="ceshi" class="eym" /><br /><br /> 城市2:<input type="text" name="ceshi" class="eym" /><br /><br /> 城市3:<input type="text" name="ceshi" class="eym" /><br /><br /> 城市4:<input type="text" name="ceshi" class="eym" /><br /><br /> 城市5:<input type="text" name="ceshi" class="eym" /><br /><br /> 城市6:<input type="text" name="ceshi" class="eym" /><br /><br /> </div> <div style=""> <input type="button" name="ceshi" value="提交" class="subcit" /> </div> <script type="text/javascript"> $(document).ready(function(){ $(".subcit").click(function(){ var city = $.trim($(".eym").val()); }); }); </script> </body></html>
展开
1个回答
2017-05-02
展开全部
$(document).ready(function(){
$(".subcit").click(function(){
var pattern = /^[\u4e00-\u9fa5]{2,4}$|^[a-zA-Z]{2,16}$/gi;
$(".eym").each(function(index,ele){
if(!pattern.test($(this).val())){
alert($(this).val() + " 不符合规则");
return false;
}
});
});
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询