Is there a way to efficiently store and reuse a Regex Validator pattern in Angular while following the DRY principle? I have a reactive formbuilder with a Regex validator pattern for ZipCode that I need to apply to multiple address forms.
I'm interested in saving the pattern /^\d{1,5}$/
so that we can simply use Validators.pattern(zipcode)
or a similar syntax in Angular.
My company also has more complex patterns for phone numbers, customer numbers, etc.
'ZipCode': [null, [Validators.maxLength(16), Validators.pattern(/^\d{1,5}$/)]],
I am looking for a way to store and easily utilize these patterns, possibly in constants.
Specifically, I am working with Angular 2:
ng-pattern to use regex from angular constants