以下两个正则表达式是有效的:
Email validation
[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$…-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?
UK Post code validation
^([Bb][Ff][Pp][Oo] ?[0-9]{1,3})$|^(([Gg][Ii][Rr] 0…hJ-Yj-y][0-9]?[A-Za-z]) ?)))[0-9][A-Za-z]{2} ?))$
但是,将它们放入Angular Reactive表单时:
address: this.fb.group({
previousPostCode: ["",
[
Validators.required,
Validators.minLength(5),
Validators.maxLength(8),
Validators.pattern(/^([Bb][Ff][Pp][Oo] ?[0-9]{1,3})$|^(([Gg][Ii][Rr] 0…hJ-Yj-y][0-9]?[A-Za-z]) ?)))[0-9][A-Za-z]{2} ?))$/)
]
],
})
我收到以下错误:Error parsing regular expression: Invalid regular expression: /^([Bb][Ff][Pp][Oo] ?[0-9]{1,3})$|^(([Gg][Ii][Rr] 0…hJ-Yj-y][0-9]?[A-Za-z]) ?)))[0-9][A-Za-z]{2} ?))$/: Unmatched ')'
。我正在使用VS 2017.有什么想法吗? 我主要对邮政编码验证感兴趣。