0

I try to customize validator for my form. Validator has two parameters: the first parameter is quantity of digits before point and the second - is quantity of digits after point. And I use these parameters to make a regexp:

new RegExp('^[0-9]{0,' + a + '}([,][0-9]{0,' + b + '})?$')

https://plnkr.co/edit/v4sWLGRHFijvQH6DfRPa?p=preview

But form still doesn't work correctly, message doesn't show if I don't follow regexp while typing into input. And I have no idea how I can use two parameters to validate template driven form using directive.

Help please

1
  • From a quick look at the plunkr, I don't think your custom validator directive is being declared in the app module, so it won't be getting picked up on the form. Also you are only passing a single parameter - '16,6' to the validator which is fine - looks like those values aren't being parsed correctly? You might also consider just using the regex with the built-in pattern validator directly rather than a custom option. Commented Sep 20, 2017 at 3:50

1 Answer 1

1

you have @Input and not @Input() in your custom-input.component, so just add the () and it'll work fine. so it'd be:

//Placeholders for the callbacks which are later provided //by the Control Value Accessor private onTouchedCallback: () => void = noop; private onChangeCallback: (_: any) => void = noop; @Input() inputPattern; //get accessor

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.