- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 09:13 AM
Hi,
How to validate a field which should accept only numbers with separators or decimals.
Eg: it should be like 0,00 or 0.00
Can someone help in the validation regex for this requirement.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 12:24 AM - edited 03-16-2023 12:26 AM
@Buddy 1 ,
Try this and let me know:
/^[0-9]{1}[,.][0-9]{2}$/
Tried and tested for many use cases and seems it worked for me.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 09:21 AM
Hi @Buddy 1 ,
The following regular expression to validate a field that should accept only numbers with separators or decimals in the format of 0,00 or 0.00:
^[0-9]+([,.][0-9]{2})?$
^ matches the start of the string
[0-9]+ matches one or more digits
([,.][0-9]{2})? matches an optional group consisting of either a comma or a dot followed by exactly two digits
$ matches the end of the string
Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 09:34 AM
Hi @Sai Shravan ,
Thanks for the reply. Currently the validation is working, but it is also accepting numbers without separators or decimals.
So it should be either 0,00 or 0.00 format. But if we try to enter only numbers like 1 or 12 , it should not accept.
Any suggestions ?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 12:10 AM
Hi @Buddy 1 ,
can you try this
^[0-9]{1,}([,.][0-9]{2})?$
Tested in the console
Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:59 AM
Hi @Buddy 1 ,
Did you get the chance to look into the solution?
Shravan
Please mark this as helpful and correct answer, if this helps you