I am working on validation of an input control when the user copy paste some value in it(当用户复制一些输入值时,我正在研究输入控件的验证)
On pasting to this input I want to strip out as below:(在粘贴到此输入时,我要剥离如下:)
Input can start with underscore or an alphabet(输入可以下划线或字母开头)
Input cannot start with number(输入不能以数字开头)
Input cannot have any spl character except underscore(输入不能包含任何SPL字符(下划线除外))
Input cannot have spaces(输入不能有空格)
This is allowed:(这是允许的:)
abc
abc_123
_123bcd
_123_bcd
This is not:(这不是:)
123abc
123_acd
abc s22
I tried with the below code:(我尝试了以下代码:)
@HostListener('paste', ['$event']) blockPaste(event: KeyboardEvent) {
this.stripInput(event);
}
stripInput(event) {
setTimeout(() => {
this.el.nativeElement.value = this.el.nativeElement.value.replace(/[^A-Za-z ]+/g, '').replace(/s/g, '');
event.preventDefault();
}, 100);
}
But with above code its not fully working, it doesnt allows: abc_123 _123_ams(但是,由于上面的代码无法完全正常工作,因此它不允许:abc_123 _123_ams)
Any inputs please(任何输入请)
ask by karen translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…