I'm trying to validate an input in Angular that can only have a maximum of 14 digits and a maximum of 2 decimals (comma separated)
The thing is that Debuggex is validating my expression as correct but in Angular doesn't work:
^[0-9]{0,14}(,?)[0-9]{1,2}$
Angular validator:
Validators.pattern(/^[0-9]{0,14}(,?)[0-9]{1,2}$/)
CodePudding user response:
Try this:
Validators.pattern(/^[0-9]{1,14}(,[0-9]{1,2})?$/)
That makes the comma including the decimal part optional.