我想驗證輸入類型=「文本」使用模式,我只想要文本。Angular 2:Validators.pattern()不工作
組件:
this.from = this.fb.group({
name: ['',[Validators.required,Validators.pattern('/^[a-zA-Z]+$/')]],
});
HTML:
<input type="text" formControlName="name"/> // omitting other html template like from tag.
上面的圖案驗證工作不適合我,它總是會返回無效狀態。
如果你確實傳遞了一個正則表達式,而不是字符串:'pattern(/^[a-zA-Z] + $ /)'會發生什麼? –
或者Validators.pattern('^ [a-zA-Z] + $')' –
謝謝@GünterZöchbauerValidators.pattern('^ [a-zA-Z] + $')工作。 –