Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

URL Validation

Arun87
Giga Contributor

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 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

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;
}

View solution in original post

17 REPLIES 17

Arun87
Giga Contributor

Hi,

Not Yet checked.

@asifnoor The above regex not working for www.google.com ---Giving Invalid URL for this also

Can you help me here ?

 

Thanks in Advance

Balaraju KB

Indrajit
Mega Guru

Hey Arun,

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;
}

 

kindly mark Correct and Helpful if applicable.

Regards,

Indrajit.