- 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
‎03-10-2024 05:53 AM
How to Set Integer Validation for multiple Variable at a Time. On change we can set condition only for one variable. Can you please help me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2020 03:57 AM
Hi there,
Since Madrid, you can apply Regex Variable Validation. So no need to write and maintain Client Scripts.
Read about it in one of my previous articles:
Service Portal Catalog Items: Regex Field Validation [Madrid]
Number is even an out-of-the-box Regex Variable Validation.
So please first investigate applying this out-of-the-box mechanism before even looking at scripting this with Client Scripts.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- 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);
}