- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 08:53 PM
I have a requirement that the value in #CPU should be more than 1 and less than 17
I achieved that using regex but it is still showing below bug. How to fix this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 11:08 PM
something like this should work
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('variableName');
newValue = parseInt(newValue);
var regex = /^(?:[2-9]|1[0-6])$/;
if (!regex.test(newValue)) {
g_form.showFieldMsg('variableName', 'Please enter a number between 2 and 16.', 'error');
g_form.clearValue('variableName');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 11:08 PM
something like this should work
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('variableName');
newValue = parseInt(newValue);
var regex = /^(?:[2-9]|1[0-6])$/;
if (!regex.test(newValue)) {
g_form.showFieldMsg('variableName', 'Please enter a number between 2 and 16.', 'error');
g_form.clearValue('variableName');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 02:06 AM
Hello @sariksorte
Just update regex as below:
^(1[0-6]|[1-9])$
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:18 PM
Hi Viraj,
I have attached one image in attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:35 PM
Hi @sariksorte
Hope you get a solution from other community members.
We can also achieve this by using below on-change client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var val = parseInt(newValue);
if(val<1 || val>17){
g_form.clearValue("cpu_count");
g_form.showFieldMsg("cpu_count","Invalid input","error");
}
}
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:47 PM
you didn't share any script which you are using then how can we help?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader