• 常见的公共函数封装方法(密码强度、手机号验证、邮箱验证、输入金额验证)


    //密码复杂度公共函数封装(邮箱,手机号)
    this.PasswordStrength = function(password) {
    var rule = Auto517.config.passwordRule.rule;
    var min = Auto517.config.passwordRule.min;
    var max = Auto517.config.passwordRule.max;

    if(rule == 0 && eval('/^[0-9]{' + min + ',' + max + '}$/.test(password)')) {
    return true;
    } else if(rule == 1 && eval('/^[a-zA-Z]{' + min + ',' + max + '}$/.test(password)')) {
    return true;
    } else if(rule == 2 && eval('/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{' + min + ',' + max + '}$/.test(password)')) {
    return true;
    } else {
    return false;
    }
    }

    //手机号验证
    this.PhoneNumberValidation = function(phonenum) {

    if(/^1[3,4,5,7,8]d{9}$/.test(phonenum)) {
    return true;
    } else {
    return false;
    }
    }

    //邮箱账号验证
    this.MailboxValidate = function(email) {

    if(/^[_.0-9a-zA-Z-]+@([0-9a-z][0-9a-z-]+.){1,4}[a-z]{2,3}$/.test(email)) {
    return true;
    } else {
    return false;
    }

    }

    //输入金额验证
    this.EnterTheAmount = function(money) {
    var rule = Auto517.config.moneyRule.rule;
    var min = Auto517.config.moneyRule.min;

    if(rule == 0 && /^[0-9]+(.[0-9]{1,2})?$/.test(money)) {
    if(money >= min) {
    return true;
    } else {
    return false;
    }

    } else if(rule == 1 && /^+?[1-9][0-9]*$/.test(money)) {
    if(money >= min) {
    return true;
    } else {
    return false;
    }

    } else {
    return false;
    }
    }

  • 相关阅读:
    852. Peak Index in a Mountain Array
    841. Keys and Rooms
    832. Flipping an Image
    821. Shortest Distance to a Character
    824. Goat Latin
    如何生成git的公钥和私钥
    学习笔记
    加快JavaScript加载和执行效率
    PO BO VO DTO POJO DAO概念及其作用
    jvm 垃圾回收区的形象说明
  • 原文地址:https://www.cnblogs.com/huguangxu/p/6243971.html
Copyright © 2020-2023  润新知