- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-08-2021 01:47 AM
Hi ,
we got requirement to check URL validation for one field.
I have written the below script , but it is always giving invalid URL (i am giving "https://development.service-now.com " for testing)
var url = g_form.getValue('u_link_to_training_materials');
//var re = /^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/;
var re = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/ ;
if (!re.test(url)) {
alert("invalid url");
g_form.disableAttachments();
return false;
}
Please help me on this if anyone is having an idea on this type of requirement
Regards
Anusha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-20-2021 07:10 AM
Thank you for marking my response as helpful.
Let me know if I have answered your question.
If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.
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
ā01-11-2021 02:36 AM
Thanks Ankur,
I will try. But could you please confirm "third line of code should be
var res = url.toString.match(re) or
var res = url.toString.match(/ain/g)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-11-2021 03:14 AM
Hi,
updated script
var url = g_form.getValue('u_link_to_training_materials');
var res = url.toString().match(/(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/g);
if (res == null)) {
alert("invalid url");
g_form.disableAttachments();
return false;
}
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
ā01-20-2021 07:10 AM
Thank you for marking my response as helpful.
Let me know if I have answered your question.
If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.
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
ā01-11-2021 03:22 AM
i think this is a valid scenerio, when you have local host address http://localhost this will satisfy.