- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:13 PM
Hi ,
What is the regular expression for validating data percentage fields is between 0 to 100 and should accept floating values
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:37 PM
Hi @Kumar38
You can use the following regular expression-
^(100(\.0+)?|(\d{1,2})(\.\d+)?)$
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:21 PM
Hi @Kumar38 ,
Try below script:
if (isLoading || newValue == '') {
return;
}
var regexp = "^(?:100.1(?:\.0)?|[0-100](?:\.[0-9])?|0?\.[1-9])$";
if(!regexp.test(newValue)){
alert('Please enter numeric value');
g_form.setValue('v_sec_review_unknown','');
}
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:37 PM
Hi @Kumar38
You can use the following regular expression-
^(100(\.0+)?|(\d{1,2})(\.\d+)?)$
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:50 PM
you can use:
^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?|0(\.[1-9])?|0)$
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 09:53 PM
hi @Kumar38 ,
You may also check this code that test the captured value to the regex and alerts if is false.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var percentageRegex = /^(100(\.0{1,2})?|\d{0,2}(\.\d{1,2})?)$/; // Regex for percentage between 0 and 100 with floating values
if (!percentageRegex.test(newValue)) {
// If the input does not match the regex, show an error message
alert('Please enter a valid percentage between 0 and 100.');
g_form.setValue(control.name, oldValue); // Reset the field value
}
}
Cheers,
Mark