【发布时间】:2019-07-04 15:47:33
【问题描述】:
目前我正在尝试限制只能输入 3 个字母和 2 个数字的输入数据。它将在单击按钮后进行检查。我的错误代码:
component.html
<input type="text" name="test3" [(ngModel)]="test3"
onkeyup="this.value=this.value.replace(/[^\a-\z\A-\Z0-9]/g,'');">
<button (click)="checkNumber3(test3)">submit</button>
component.ts
checkNumber3(test3): void {
console.log(test3);
if (test3 !== test3.match(/([a-z])+/) * 2 || test3 !== test3.match(/([A-Z])+/) * 2
&& test3 !== test3.match(/([0-9])+/) * 3
) {
alert('only can input 2 letters plus 3 numbers');
} else {
alert('correct');
}
}
感谢您的帮助!
【问题讨论】:
-
它做错了什么?
-
老兄,你的意思是我的代码或我的帖子由 mr.pimpale 编辑?
-
您的代码。他在问它是如何行为不端的,它应该如何表现。 Prashant 的修改尚不可见。
标签: javascript html angular angular-directive