- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 09:47 AM
I have field called folder. where i have to allow only
x:\folder or
x:\\folder or
x:\folder\folder\ or
x:\\folder\folder or
x:\\folder\\folder etc etc
Can i anyone help me with onchange client scipt for this ? I Have tried below code, but getting accurate result..
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regExp1 = /\\[a-z]+\\[a-z]+$/i;
var isValid1 = regExp1.test(newValue);
if(!isValid1) {
g_form.addErrorMessage("Enter proper path");
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 06:41 PM
Try this instead
/^([a-zA-Z]:)*\\+(\w+\\+)*\w*$/.test(yourString);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 09:50 AM
Please use below reg ex in your code
^[a-zA-Z]:\\(\w+\\)*\w*$
Then in your client script, you could check if a string matches by
/^[a-zA-Z]:\\(\w+\\)*\w*$/.test(yourString)
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 05:49 PM
its working for only this value x:\folder
But not for this
x:\\folder or
x:\folder\folder\ or
x:\\folder\folder or
x:\\folder\\folder or
folder\\folder or
\\folder\folder

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 06:41 PM
Try this instead
/^([a-zA-Z]:)*\\+(\w+\\+)*\w*$/.test(yourString);
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2019 07:46 PM
Has this solved your issue?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022