<script> // 正则检测手机号是否正确 var poho = "13915605430"; // ^开头; // & 结尾 if(poho.match(/^139\d{8}$/i)){ alert("输入正确"); }else{ alert("输入错误"); } </script> 检验邮箱是否正确; <script> var email = "[email protected]"; if(email.match(/^\[email protected]\w+\.\w+$/i)){ alert("邮箱输入正确"); }else{ alert("邮箱输入有误,请检查"); } </script> 高级检索替换,注意$的运用; <script> var date = "2016/05/11"; // 2016-05-11 var time = date.replace(/(\d+)\/(\d+)\/(\d+)/g,"$1-$2-$3"); // 没有()是不可以的,就没有$的本领的; alert(time); </script>
时间: 2024-11-05 10:27:10