【问题标题】:Angular one of the conditions is to check the password field for certain characters only [! @ $% & *]Angular 的条件之一是仅检查某些字符的密码字段 [! @$% & *]
【发布时间】:2019-11-14 17:42:12
【问题描述】:
checkParams(event) {

    if (event.length > 8 && event.length <= 30) {
        this.passLength = true;
    } else {
        this.passLength = false;
    }
//quantity check

    if (event.search(/[0-9]/) > -1) {
        this.passNumbers = true;
    } else {
        this.passNumbers = false;
    }
//number check

    if (event.search(/[!@$%&*]+/) > -1) {
        this.passSpecial = true;
    } else {
        this.passSpecial = false;
    }
//character check

    if (event.search(/[a-z].*[A-Z]|[A-Z].*[a-z]/) > -1) {
        this.passUpper = true;
    } else {
        this.passUpper = false;
    }
//check upper case 

    if (event.search(/^\S*$/)) {
        this.passSpace = false;
    } else {
        this.passSpace = true;
    }
//check whitespace

【问题讨论】:

    标签: html regex angular angular8


    【解决方案1】:
            if (event.search(/[!@$%&*]+/) > -1 && event.search(/[~`#^()_={}[\]:;,.<>+\/?-]+/) <= -1) {
            this.passSpecial = true;
        } else {
            this.passSpecial = false;
    
        }
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用以下单一模式:

      ^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@$%&*]).{9,30}$
      

      你的 Angular JS 代码:

      if (event.search(/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@$%&*]).{9,30}$/) > -1) {
          this.passValid = true;
      }
      else {
          this.passValid = false;
      }
      

      【讨论】:

      • 是的,我想这样做,但我需要密码输入条件才能改变颜色。例如: - 密码必须包含特殊符号(*、!、$、%、&、@) - 密码必须包含数字 - 密码不得包含空格 - 如果为真,密码必须匹配,然后以绿色突出显示
      • 是的,但是您建议如何用一种颜色处理多个逻辑条件?例如。缺少数字和缺少大写字母...颜色是什么?
      • 我将分享一个截图。 paste.pics/072d121589b5364008db20340c04d1cb
      • “密码必须包含特殊符号” - 嗯。还有比这些更多的特殊符号。而且,老实说,大多数此类要求只是使密码为easy to brute force and hard to remember。我的意思是,没有间隙?为什么? :-\
      猜你喜欢
      • 2014-05-07
      • 2015-03-15
      • 2013-04-01
      • 2011-09-25
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2012-04-22
      • 2011-07-13
      相关资源
      最近更新 更多