- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 03:01 AM
i am trying write client script to check the field contains 0, 00, 000, and negative values. but the below script working for 0. it didnt shows error msg - 00, 000.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.addInfoMessage("the new value="+newvalue);
var value = g_form.getValue('fieldname');
var regEx = /^\d+(\.\d+)*$/;
if (!regEx.test(newValue)) {
g_form.showFieldMsg('fieldname', 'Value must be greater than 0', 'error');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 03:48 AM
Hi @Deepa12 ,
I trust you are doing great.
the first thing I would suggest is to modify the regular expression used in the script to include the additional cases you want to check for. For example, to check for values containing 0, 00, and 000, you could modify the regular expression to:
var regEx = /^([1-9]\d*|0)(\.\d+)?$/;
This modified regular expression will match any non-negative number that is not a pure zero, and will also match values containing a single zero, two zeros, or three zeros before the decimal point.
To check for negative values, you could modify the if statement condition as follows:
if (!regEx.test(newValue) || parseFloat(newValue) < 0) {
This will check whether the new value is not a valid non-negative number or is less than zero, and display an error message accordingly.
Please mark the answer correct if it was helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 03:48 AM
Hi @Deepa12 ,
I trust you are doing great.
the first thing I would suggest is to modify the regular expression used in the script to include the additional cases you want to check for. For example, to check for values containing 0, 00, and 000, you could modify the regular expression to:
var regEx = /^([1-9]\d*|0)(\.\d+)?$/;
This modified regular expression will match any non-negative number that is not a pure zero, and will also match values containing a single zero, two zeros, or three zeros before the decimal point.
To check for negative values, you could modify the if statement condition as follows:
if (!regEx.test(newValue) || parseFloat(newValue) < 0) {
This will check whether the new value is not a valid non-negative number or is less than zero, and display an error message accordingly.
Please mark the answer correct if it was helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi