- 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 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
03-16-2020 09:01 AM
PLEASE, DO NOT USE THE ACCEPTED SOLUTION, IT IS NOT WORKING CORRECTLY.
Example: the mentioned RegEx validates to true using this URL: httpsss.safdgoiuhasdg
httpsss.safdgoiuhasdg is not a valid URL.