- 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: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:43 AM
Thank you @Hemant Goldar for your prompt response.
It works perfectly for restricting numbers after decimal places.
Can we also restrict numbers before decimal places to 4 or max 5 digits?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:47 AM
Hi @Suryansh Verma,
Can you provide me the list of valid numbers that should accept and shouldn't be?
And please mark the previous comment as the correct answer to close the thread.
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:50 AM
so it should accept
-12345.897 or -12345,897 but not -1234555555555.897 or -1234555555555,897