
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2016 12:29 PM
Greetings all,
I'm looking for some assistance on syntax for a series of start withs
IE if it startswith ABC, or XYZ or CAT.
I know it's a on change script for the variable, just not sure on how to match characters. (case insensitive)
Any thoughts?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2016 01:35 PM
Here's one way to do it using test():
if (/^(ABC|XYZ|CAT)/i.test(value)) { /* process TRUE condition */ } // starts with ABC or XYZ or CAT, ignore case
Hope this helps.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
John Chun, PhD PMP ![]() | ![]() |
Winner of November 2016 Members' Choice Award
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2016 12:32 PM
ServiceNow also supprots Regex so use SNC Regex API - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2016 01:07 PM
Here is the sample script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue.match(/^ABC|XYZ|CAT/i))
{
return true;
}
else{
alert('Fail');
g_form.clearValue('You Field Name');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2020 01:33 PM
This on-change client script worked perfectly for me - We have two fields on our work orders that require information from another system and folks were always entering the wrong things. Here's my version:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue.match(/^SO/i))
{
return true;
} else {
alert('The Sales Order number must begin with SO...');
g_form.clearValue('u_salesorder');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2016 01:35 PM
Here's one way to do it using test():
if (/^(ABC|XYZ|CAT)/i.test(value)) { /* process TRUE condition */ } // starts with ABC or XYZ or CAT, ignore case
Hope this helps.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
John Chun, PhD PMP ![]() | ![]() |
Winner of November 2016 Members' Choice Award