• JS表单验证优化


    var validate = (function(){
      var messages = {
          isEmail : '输入正确格式邮箱',
          isPhoneNum : '输入正确手机号'
      };
    
      var validateTypes ={
          isEmail:function(value){
            var reg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
            if(!reg.test(value)){
                return true;
            }
            return false;
          },
          isPhoneNum:function(value){
              var reg = /^1[34578]d{9}$/;
              if(!reg.test(value)){
                  return true;
              }
              return false;
          }
      };
      return function(value,type){
          if(validateTypes[type](value)){
              return messages[type];
          }
      }
    })();
    
    console.log(validate("","isEmail")); //输入正确格式邮箱
    console.log(validate("bilibiligo@gmail.com","isEmail")); //undefine
    console.log(validate("test","isPhoneNum")); //手机号
    console.log(validate("18824156554","isPhoneNum")); //undefine
  • 相关阅读:
    LeetCode.152
    python
    python
    python
    python
    python
    python
    python
    PyCharm2020.1激活码破解教程
    Python GUI编程(Tkinter)17、Menu鼠标右键菜单
  • 原文地址:https://www.cnblogs.com/rlann/p/9505968.html
Copyright © 2020-2023  润新知