Question

Decimal Validation Pattern

  • 31 December 2020
  • 5 replies
  • 49 views

Badge +2

Need help with a validation pattern on a text field to only allow 3 digits and 3 decimal points

(e.g. 123.123)

 

Thanks!


5 replies

Userlevel 4
Badge +8

Something like this: ^[0-9]{1,3}(?:\.[0-9]{1,3})?$

Userlevel 3
Badge +6

Hi @DMojo,

This may also work (The user has to enter the comma though or else it reads as a whole number):
 

^[0-9]{3}(\.[0-9]{3})?$

Kind Regards

Prineel

Userlevel 3
Badge +6

Hi @DMojo,

Putting a “.” in the middle may work:

^[0-9]{3}.(\.[0-9]{3})?$
It will accept a value like “123.” and probably read the decimals as null but it doeds not allow 3 decimals for some odd reason

 

Kind Regards

Prineel

Badge +2

Thanks so much for the input guys!!! 

 

Using 

^[0-9]{3}.(\.[0-9]{3})?$

I get the result below:

(If the user enters 123123 into the field)

I need the result to be 123.123

So the user can enter up to 6 numbers, 3 before 3 after the decimal.

 

I appreciate the help so far.  Please let me know if you think of anything else that might work.

Kind Regards!

Userlevel 3
Badge +6

Hi @DMojo,

This expression works better as it validates 3 didgits after a comma:

^[0-9]{3}.(?:[0-9]{3})?$

Im still not sure how to convert a number to a decimal with the expression so it wont work with a integer.

 

Kind Regards

Prineel

Reply