邮箱验证

    1. <input type="" name="" id="emial" placeholder="请输入邮箱">
    2. <script>
    3. var emial=document.getElementById("emial");
    4. emial.onkeydown=function(){
    5. if(event.keyCode==13){
    6. var value=this.value.trim();
    7. var reg=/^[\w]+@[0-9a-z]+\.[a-z]+$/;
    8. console.log(reg.test(value));
    9. }
    10. }
    11. </script>

    银行卡密码验证

    1. <input type="password" id="input2" placeholder="请输入密码" >
    2. <script>
    3. //密码验证
    4. var input=document.getElementById("input2");
    5. input2.onkeydown=function(){
    6. if(event.keyCode==13){
    7. var value=this.value.trim();
    8. var reg=/^\d{6}$/; //6位密码
    9. console.log(reg.test(value));
    10. }
    11. }
    12. </script>

    用户密码验证

    1. <input type="password" id="input" >
    2. <script>
    3. //用户密码验证
    4. var input=document.getElementById("input");
    5. input.onkeydown=function(){
    6. if(event.keyCode==13){
    7. var value=this.value.trim();
    8. var reg=/^[A-z]\d{5,}$/; //以字母开头,后面至少5位数字
    9. console.log(reg.test(value));
    10. }
    11. }
    12. </script>

    电话号码

    1. <script>
    2. var str="18674187236"
    3. //严格匹配 ^以……开头 $以……结尾
    4. var reg=/^1[3-9]\d{9}/;
    5. console.log(reg.test(str))
    6. </script>

    过滤标签

    1. var str="<p>我是</p>。<div>你好</div>"
    2. var reg=/<[^<>]+>/g; //
    3. console.log(str.replace(reg,""));//我是。你好