Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
kabir khan
Website Validation(URL)
February 18, 2013 7:18 AM
Answer

kabir khan

Rank: New Member

Posts: 21

Join Date: February 15, 2013

Recent Posts

Hi friends,

My requirement is to validate my form,
I have achieved validation for all things except only one things website validation(url)
.If I give validation for url means it only accepted the website start by eg:http(http:www.liferay.com)

My Requirement
But my requirement is to accept both the things it should may accept both http or without http.so friends kindly give your valuable thoughts for me ..
Subhash Pavuskar
RE: Website Validation(URL)
February 18, 2013 8:35 AM
Answer

Subhash Pavuskar

Rank: Regular Member

Posts: 234

Join Date: March 12, 2012

Recent Posts

Hi

If you want to use the regex you already have, but make http and https optional. See following:
var pattern = /((http|https):\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
kabir khan
RE: Website Validation(URL)
February 18, 2013 9:38 PM
Answer

kabir khan

Rank: New Member

Posts: 21

Join Date: February 15, 2013

Recent Posts

Subhash Pavuskar:
Hi

If you want to use the regex you already have, but make http and https optional. See following:
var pattern = /((http|https):\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;




Thank You for your reply.....'


I have achieved validation by using aui validator only ,


So can u explain briefly about to achieve these validation,I have one doubt whether javascript or jquery can be used in the aui form
...

Please help me
Subhash Pavuskar
RE: Website Validation(URL)
February 18, 2013 10:11 PM
Answer

Subhash Pavuskar

Rank: Regular Member

Posts: 234

Join Date: March 12, 2012

Recent Posts

Hi kabir khan,

You can have a look at this link !! Click Here
Hope that may help you to understand !!

And Below code is using Jquery validation

 1$.validator.addMethod("cus_url", function(value, element)
 2     {
 3    if(value.substr(0,7) != 'http://')
 4        {
 5        value = 'http://' + value;
 6    }
 7    if(value.substr(value.length-1, 1) != '/')
 8        {
 9        value = value + '/';
10    }
11    return this.optional(element) || /^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test(value);
12        }, "Not valid url.");
kabir khan
RE: Website Validation(URL)
February 19, 2013 1:17 AM
Answer

kabir khan

Rank: New Member

Posts: 21

Join Date: February 15, 2013

Recent Posts

Subhash Pavuskar:
Hi kabir khan,

You can have a look at this link !! Click Here
Hope that may help you to understand !!

And Below code is using Jquery validation

 1$.validator.addMethod("cus_url", function(value, element)
 2     {
 3    if(value.substr(0,7) != 'http://')
 4        {
 5        value = 'http://' + value;
 6    }
 7    if(value.substr(value.length-1, 1) != '/')
 8        {
 9        value = value + '/';
10    }
11    return this.optional(element) || /^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test(value);
12        }, "Not valid url.");


Thanks You ,It helps me lot .... Subhash Pavuskar