<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><form method="post" class="form-horizontal" role="form" action="" id="myform"> <input id="testid" name="testid" value=‘‘ > <button onclick="f($(‘#testid‘).val())" type="button" id="smsbtn" class="btn btn-success">验证</button></form><script language="JavaScript"> function isPassword(){//连续三位数字相同 var str = $("#testid").val(); //var patrn=/(.)*(.)\2{2}(.)*/g; var patrn = /(\w)*(\w)\2{2}(\w)*/g; if (patrn.test(str)){ alert(‘ture‘) //verify false }else{ alert(‘false‘); //verify true } } function f(a){ //连续2位数字递增或递减 //console.log(a); if(a.length<2){ return alert(‘111‘); } var t=a.charCodeAt(0)-a.charCodeAt(1); console.log(t); for(var i=0;i<a.length-1;i++){ if((a.charCodeAt(i)-a.charCodeAt(i+1))==-1 || (a.charCodeAt(i)-a.charCodeAt(i+1))==1 ){ return alert(‘true‘) //verify false }else{ return alert(‘false‘) //verify true } } } </script><script src="js/jquery-1.11.3.js"></script></body></html>
时间: 2024-10-09 20:49:16