[英]Do I need required if the pattern already implement this aspect?
I want some fields in a form to be required and to respect some pattern. 我希望表单中的某些字段是必需的,并且要尊重某些模式。
Currently I have this : Validators.required, Validators.pattern('^[0-9-_\\/]+$')
当前我有这个: Validators.required, Validators.pattern('^[0-9-_\\/]+$')
but I was curious, is the .required is needed since the + in the regex already specify I need more than 0 element ? 但我很好奇,因为正则表达式中的+已经指定我需要大于0的元素,所以需要.required吗? Is there anything the required validators does that a '.+' regex wouldn't already have ? 是否有需要的验证程序执行“。+”正则表达式所没有的任何内容?
This is only for UI purposes. 这仅用于UI。
One will display the pattern error, the other one the required error. 一个将显示模式错误,另一个将显示所需的错误。
If you wish to display distinct errors, then you should keep it. 如果您希望显示明显的错误,则应保留该错误。
Otherwise, if you simply display "Error on the form" (or something alike), then no, you don't need to use the required validator. 否则,如果仅显示“表单上的错误”(或类似内容),则否,则无需使用所需的验证器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.