- 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 08:57 PM
Hi @sariksorte
Refer below post and change the regex as
^(0?[1-9]|1[0-7]|)\b$
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:13 PM
Hello @sariksorte
I am not sure what your bug as I cannot see anything in screenshot as bug.
You can use below regex for your requirement:
^(1[0-6]|[2-9])$
Check below thread which will give idea how to use it:
Service Portal Catalog Items: Regex Field Validati... - ServiceNow Community
Regex Validation - ServiceNow Community
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:27 PM
Hello @sariksorte
Follow below steps:
1) Create record under Variable Validation regex table.
2) Use same regex in your variable created as show below:
3) Now showtime check over portal:
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 10:38 PM
It is working for 2 to 16 but it is not working for 1.