Home > Net >  RegEx expression maximum 14 digits and maximum 2 decimals
RegEx expression maximum 14 digits and maximum 2 decimals

Time:03-30

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}$/)

enter image description here

CodePudding user response:

Try this:

Validators.pattern(/^[0-9]{1,14}(,[0-9]{1,2})?$/)

That makes the comma including the decimal part optional.

  • Related