- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 08:07 PM
Hi Team, I have single line text variable on the form. User have to enter only numbers starting with 00 always, if they enter alphanumeric values or alphabets then we should not allow user to submit request. Fox Example, if they enter 00asdf34 on the variable then request should not submit, if they 'akfjkjf', then request should not submit, if they enter 753839, then request should not submit, if they enter 001234, then user should need access to submit request. Please help me to validate this variable. Thank you.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 08:59 PM
Hi,
So only numbers are allowed and that too starting with 00 followed by only digits
You can use variable validation regex and apply that on your string variable and no need of any client script etc
Regex - ^[00]{2}[0-9]*$
1) Create variable validation regex from left nav
2) then attach this to string variable under type specifications
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 08:34 PM
Hi Gowtham,
Please refer this link,
https://community.servicenow.com/community?id=community_question&sys_id=eb0e96a81bf72010a17c62c4bd4bcb6b
Please mark as helpful or correct, if this solution helps you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 08:55 PM
Hi Gowtham,
You can write an onChange client script on that text field with the following code:
var number = g_form.getValue('your field Name'); // put your variable name here
if(number.startsWith("00")){
var splitVal = number.split("00");
var shouldNumeric = splitVal[1];
if(isNaN(parseInt(shouldNumeric))){
alert("Number must contain numbers only after 00");
g_form.setValue('number',''); // put phone nnumber field name correctly here
}
}else{
alert("Number must start with 00");
g_form.setValue('number',''); // put phone nnumber field name correctly here
}
Regards,
Mahesh Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 08:59 PM
Hi,
So only numbers are allowed and that too starting with 00 followed by only digits
You can use variable validation regex and apply that on your string variable and no need of any client script etc
Regex - ^[00]{2}[0-9]*$
1) Create variable validation regex from left nav
2) then attach this to string variable under type specifications
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2021 09:33 PM
Hi,
Onchange client script to validate the input should only be number
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^[0-9.]*$/;
if(!pattern.test(newValue)){
alert('Enter only Number');
g_form.setValue('field_name', '');
}
//Type appropriate comment here, and begin script below
}
onsubmit client script so that it should not be able to submit until it has '00' in the first place
function onSubmit() {
//Type appropriate comment here, and begin script below
var val=g_form.getValue('number');
if(val.indexOf('00') > -1)
{
return true;
} else
{
g_form.showFieldMsg('number', "It Should start with 00", 'error');
return false;
}
}
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman