- 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:23 PM
Instead of that you can use simple way to verify if it will fulfill the your requirement because regex is combination of pattern.
Regex can use only for numeric also but below is most recommended. (isNaN)
var rajababuVar=g_form.getValue('field name');
if (isNaN(rajababuVar)) //check if value is not numeric
-=----------
For Regex you can check on below site
https://regexr.com/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 10:46 PM
FYI, about the regular expression. "." is a special character in regular expression so it needs to be escaped.
var regexp = /^[0-9]*[\.]?[0-9]*$/; // may or may not have fractional. Fractional should also be numeric
if (!regexp.test(newValue))
{
alert('It should be numeric fractional entry only');
g_form.setValue('u_effort', '');
}
or
var regexp = /^\d*[\.]?\d*$/;
if (!regexp.test(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-11-2022 04:05 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 04:22 AM
The script show error if there's a space. To allow spaces, just trim() newValue in the test statement. (My bad on the period in regular expression. It's not needed).
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
if (!regexp.test(newValue.trim())) {
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-11-2022 04:27 AM