循环遍历正则验证input框内容合法性
<!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> 循环遍历正则验证input框内容合法性</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta name="author" 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" value="" /><br /><br /> 城市2:<input type="text" name="ceshi" class="eym" value="" /><br /><br /> 城市3:<input type="text" name="ceshi" class="eym" value="" /><br /><br /> 城市4:<input type="text" name="ceshi" class="eym" value="" /><br /><br /> 城市5:<input type="text" name="ceshi" class="eym" value="" /><br /><br /> 城市6:<input type="text" name="ceshi" class="eym" value="" /><br /><br /> </div> <div style=""> <input type="button" name="cei" value="提交" class="subcit" /> </div> <script type="text/javascript"> $(document).ready(function(){ $(".subcit").click(function(){ function isLength(obj){ var reg=/^[\u4e00-\u9fa5]{2,10}$/; //2-10个汉字 if(!reg.test(obj)){ alert('输入内容不合法');return; }else{ alert('输入正确'); } } var $checkArray = $("input[name='ceshi']"); if(!$checkArray)return; for(var i=0;i<$checkArray.length;i++){ var value=$checkArray[i].value; isLength(value); } }); }); </script> </body> </html>