- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 07:51 AM
Hi All,
I have created a single line variable field for catalog item. Now i want to validate the url. Kindly help on this how to achieve this. Thanks in advance
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2020 12:16 PM
Hi,
I have modified the script of willem slightly to exclude www. Check this.
var url=newValue;
var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
if(url.indexOf("www.") > -1 || !re.test(url)) {
g_form.showFieldMsg('your field', 'invalid url');
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 07:58 AM
Hi Arun,
var url = g_form.getValue('url_field');var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
if (!re.test(url)) {
alert("invalid url");
return false;
}I hope it will help you.
Please mark helpful and Correct if it helps.
Thanks..!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 08:00 AM
Hi Jyoti,
It is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 08:16 AM
Hi Arun,
please check below links for help
URL variable validation not working in Service Portal as it does in DesktopUI
URL validation for a request form
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
09-09-2020 08:37 AM
You can create onChange client script on the URL field to validate:
replace your field with the url field
var url = g_form.getValue('your field');
var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
if (!re.test(url)) {
g_form.showFieldMsg('your field', 'invalid url');
return false;
}