The following two regular expressions are valid ones:
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} ?))$
However, when putting them into Angular Reactive forms:
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} ?))$/)
]
],
})
I am getting the following error: 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 ')'
. I am using VS 2017. Any idea? I am mainly interested in the post code validation.