尝试使用reg表达式验证电话号码。但无法正常工作。怎么办?有知道的帮忙看看解决办法吗
示例:电话号码,例如 +1 454 777788756
constructor(private formBuilder: FormBuilder) {
this.myForm = formBuilder.group({
phone: [
'',
[
Validators.required,
Validators.pattern(
'/^\\+([0-9]{1,3})?[- ]?(\\d{3})?[- ]?(\\d{3})[- ]?(\\d{4,6})( ext \\d{4})?$/'
)
],
],
});
}
演示:https://stackblitz.com/edit/angular-g7vtuj-mubqry?file=app%2Fselect-multiple-example.ts