- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:50 AM
I have a text variable and I want the user should enter only numbers not text
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:57 AM
Create onChange client script select the particular variable and try below code
var value = g_form.getIntValue("<variable_name>");
if(isNaN(value)||isNaN(newValue)||(newValue < 0)){
g_form.showFieldMsg('<variable_name>','Please enter a numeric positive value!','error');
return;
}else{
g_form.clearMessages();
g_form.hideFieldMsg('<variable_name>',true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:52 AM
Hi Mahfooz,
Use Out-of-box regular expressions to fulfill this criteria.
Go to your variable > "Type specifications" section > Select Validation Regex "Number" from drop-down list. > Save it.
In case, "Number" is not present in drop-down. Create new Validation Regex following this path: Service catalog > Variable Validation Regex > Create New.
Mark this response as correct/helpful if you find it helpful.
Regards,
Shubham

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:52 AM
Hi
check here:
Regards
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:53 AM
Try a catalog client script.
extract the value "on change".
is the isNaN native javascript function to validate.
https://www.w3schools.com/jsref/jsref_isnan.asp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:56 AM
Hi,
write onchange client script on that text variable
UI Type - ALL
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^([0-9]+[0-9])/;
if(!regexp.test(newValue))
{
alert('Only numbers are allowed');
g_form.clearValue('variableName');
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader