I need to run validation on one of the form fields in my app. For this, I am using ReactiveFormsModule
My pattern as follows:
domainPattern = '^(((?!-))(xn--|_{1,1})?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$';
I am using the above pattern in my pattern Validator code as follows:
this.customerForm = this.formBuilder.group( {
name: [ '' ],
company: [ '' ],
email: [ '', [ Validators.required, Validators.email ] ],
domain: [ '', [ Validators.required, Validators.pattern( this.domainPattern ) ] ]
} );
For email
it's standard working well.
But for the custom domain regex doesn't work for me. I have used regex from here.
Based on the questions reviewed it seems difficult to find general domain name regex for all of the valid domains but I want to cover most basic cases.
The current pattern shows: $#$#.com
, abcd
as valid domains.
Do Validators have any constant validator similar to Validators.email
for the domain?