- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 03:55 AM
Hi All,
I need to restrict a field to enter only positive values.
I have written the below client script,but the field is allowing values starting with '-', for example -22.
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
if (newValue != '') {
//get the integer value of the field
var v_cost_center = g_form.getIntValue('software_maintenance_cost');
//check to see if there are any non numeric characters in the string
if ((isNaN(newValue) == true)|| (nbrwn < 0) || isNumber(newValue)<0)
{
alert("Please enter Numeric Values.");
g_form.setValue('software_maintenance_cost', '');
}
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:30 AM
Here we go.
check the below script. i used regex to restrict the -ve number.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var specialCharRegex =/^\d{0,10}(\.\d{0,2})?$/g;
if(!specialCharRegex.test(newValue)){
alert('Please do not enter -ve value');
g_form.setValue('description','');
}
}
hope it will help you.
Thanks,
Harshvardhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:06 AM
Hi lakshmi,
var v_cost_center = g_form.getIntValue('software_maintenance_cost');
what is getting retuirned in v_cost_center. Check the output by placing alert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:12 AM
Hi Sneha,
If I enter -22 it is returning -22.For 2.2 it is showing 2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:25 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:30 AM
Here we go.
check the below script. i used regex to restrict the -ve number.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var specialCharRegex =/^\d{0,10}(\.\d{0,2})?$/g;
if(!specialCharRegex.test(newValue)){
alert('Please do not enter -ve value');
g_form.setValue('description','');
}
}
hope it will help you.
Thanks,
Harshvardhan