0
votes

In the above example,I have a reactive form with nested form groups.address-form child component is used for the nested form group.The validation is being done in the parent component.Everything seems working except the pattern validation.The validation for required works fine but the pattern validation does not work.

I have used the validators.compose to club together required validation and pattern validation.Is there anything i am doing wrong here?

1
Your demo works for me. When I put 2222222222222222, it accepts. And it fails with message, 'Address should follow the pattern', if otherwise. By the way, both 'required' and pattern validators work from my Chrome browser. So, what is the question again? - Ashokan Sivapragasam
I was just thinking that i would get both the error messages..Does this pattern accepts empty string?..Sorry if this is lame i am new to this - Sathya Narayanan GVK
Have you changed something in Stackblitz sample? - Ashokan Sivapragasam
yes I removed the required validation - Sathya Narayanan GVK
Passing formGroup to a child component is a bad practice because you let a child access an object which has way more than it should. I've made a full post about that here stackoverflow.com/a/56375605/2398593 and you should also just check github.com/cloudnc/ngx-sub-form library for that - maxime1992

1 Answers

1
votes

As for me, you validation pattern, enter: 1234567890123456. What kind of information do you want to validate?) Also you can replace it with

address1: ['',Validators.pattern('^\\d{16}$')]