- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2016 08:47 PM
Hi,
I have a client requirement to have a request form field "URL". Basically, asking users to enter a URL of the site they manage. Requirement is to validate the URL if it is valid. How would I do that considering I have validation criteria?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2016 11:44 PM
Hi Ronald,
You can use a regex to validate url.
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2016 08:49 PM
What was your initial thought on validation?
Like is it a live website?
or is it on a list, that you have valid URL's stored in a table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2016 08:56 PM
general validation like to avoid user entering "mysite" instead of proper terminology as "www.mysite.com". To your second question, there is no list of valid urls anywhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2016 09:11 PM
not the best idea, but a very simple idea would be and indexOf("www.") > -1
that will ensure that it at least has a www. in it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2017 08:56 AM
Many URL's don't have www, especially internal sites.