- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:33 AM
Hello Community,
I have a string field for inputting hours.
The field should only allow negative numbers & decimal(.) & also comma(,) for that i am using the below expression.
/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:(\.|,)\d+)?$/
now I also want to restrict the decimal places (before and after ) to upto 3 digits only and also
so accepted value should be
-123.456 or -123,456 and not -1234.5678 or -1234,5678
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:38 AM
Hi @Suryansh Verma,
Please try the below regular expression
^-?(?:\d{1,3}(?:,\d{3})*|\d+)([.,]\d{1,3})?$
I hope this helps!
Regards,
Hemant
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:54 AM
@Suryansh Verma here is the regular expression - ^-?\d{1,10}([,.]\d{1,3})?$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:59 AM
@Hemant Goldar Perfect !!!
Thanks for your help.