首页 > 解决方案 > Angular 中用于设置验证的正则表达式

问题描述

我在Angular中有这样的功能:

checkRegex() {
setTimeout(() => {
const  regex = /^(?=.{8,})(?=.[A-Z])(?=.[a-z])(?=.[0-9])(?=.[!@#$%^&()=])([a-zA-Z0-9!@#$%^&()=-]+)$/g;
let checkListCondition = this.listCondition[0];
let checkValue = checkListCondition.value[0]
const matchRegex = checkValue.test(regex)
if (matchRegex) {
  this.state.disableGroup.submitButton = false;
} else {
  this.state.disableGroup.submitButton = true;
}

console.log('checkValue', checkValue);
}, 10);

}

我的期望是如果我输入这样的值:

<测试'

this.state.disableGroup.submitButton 将返回 false,如果我输入这样的值:

(成功^

this.state.disableGroup.submitButton 将返回 true

在我的代码中,你能帮我找出我的错误在哪里吗?谢谢你。我当前的代码不起作用。我需要你们的帮助

标签: javascriptangularregex

解决方案


推荐阅读