- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 10:14 PM
Hi,
I have a requirement, on "Change Request" there is field Effort Estimation "Type : String". In that field only numeric value should be filled eg: 23.55, 345, 56. For that I have written a onChange client script. Values like ASdsf233 and asd.345 are cleared But it is taking value "123Asfdg" ,"456.fgj" How to clear values like 65768Asdgf.
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regexp = /^[0-9].*$/;
if (!regexp.test(newValue))
{
alert('It should be numeric fractional entry only');
g_form.setValue('u_effort', '');
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 04:47 AM
Another option is to trim the spaces and test the trimmed value.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[0-9]*(.)?[0-9]*$/; // may or may not have fractional. Fractional should also be numeric
var str = newValue.trim(); // trim leading and ending spaces
if (!regexp.test(str)) {
g_form.clearValue('u_effort');
g_form.showFieldMsg('u_effort', 'It should be numeric fractional entry only', 'error');
} else if (str != newValue) { // if there was leading or ending spaces, set the value to trimmed value
g_form.setValue('u_effort', str);
}
}
Execution result.
1. Enter " 5678 "
2. Press tab key.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 10:22 PM
Hi,
Please check below link and use one fitting your requirement.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 10:22 PM
Why use regular expression.
if (isNaN(newValue)) {
alert('It should be numeric fractional entry only');
g_form.setValue('u_effort', '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 10:34 PM
Thank You Hitoshi it is working for me now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:11 PM
Hitoshi,
Using isNan allows the mathematical constant e
Field will have values like 1e1, 1000e344 etc