[英]angular reactive form pattern validator only allow text, numbers and some characters
I am using angular 10 and reactive forms.我正在使用 angular 10 和反应形式。 I need a input to only accept (letters, numbers, and this 2 characters "_" and "-") I've tried letters and numbers with this:
我需要一个只接受(字母、数字和这 2 个字符“_”和“-”)的输入我试过用这个字母和数字:
Validators.pattern('[a-zA-Z ][0-9]*')]
The above only works if I do it this way:以上仅适用于我这样做的情况:
Validators.pattern('[a-zA-Z ]*')]
But I also need it to allow numbers and - and _但我也需要它来允许数字和 - 和 _
How can I do this?我怎样才能做到这一点?
Your code become你的代码变成
Validators.pattern('[-_a-zA-Z0-9]*')]
Edit: Based on comments by @ekalin编辑:基于@ekalin 的评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.