- 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-11-2020 12:24 PM
You can check the value if it contains www. with indexOf like asifnoor added. You then can remove the www. from the regex like so:
var url = newValue;
var re = /^(http[s]?:\/\/){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-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-14-2020 03:48 AM
Hello Arun
If this has answered your question, kindly mark the comment as a correct answer and also helfpul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 04:55 AM
The above mentioned script is working for me to validate the url. The script will validate the url contains only http and https. If www is mentioned in the url it not allow the user to submit the request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 05:02 AM
Have you tested my code as well? That contains an updated regex, which is better for performance and does not contain unneeded check.