Fórum

Website Validation(URL)

thumbnail
kabir khan, modificado 11 Anos atrás.

Website Validation(URL)

New Member Postagens: 21 Data de Entrada: 15/02/13 Postagens Recentes
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 ..
thumbnail
Subhash Pavuskar, modificado 11 Anos atrás.

RE: Website Validation(URL)

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
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#!:.?+=&%@!\-\/]))?/;
thumbnail
kabir khan, modificado 11 Anos atrás.

RE: Website Validation(URL)

New Member Postagens: 21 Data de Entrada: 15/02/13 Postagens Recentes
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
thumbnail
Subhash Pavuskar, modificado 11 Anos atrás.

RE: Website Validation(URL)

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
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

$.validator.addMethod("cus_url", function(value, element) 
     { 
	if(value.substr(0,7) != 'http://')
        {
		value = 'http://' + value;
	}
	if(value.substr(value.length-1, 1) != '/')
        {
		value = value + '/';
	}
	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); 
        }, "Not valid url.");
thumbnail
kabir khan, modificado 11 Anos atrás.

RE: Website Validation(URL)

New Member Postagens: 21 Data de Entrada: 15/02/13 Postagens Recentes
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

$.validator.addMethod("cus_url", function(value, element) 
     { 
	if(value.substr(0,7) != 'http://')
        {
		value = 'http://' + value;
	}
	if(value.substr(value.length-1, 1) != '/')
        {
		value = value + '/';
	}
	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); 
        }, "Not valid url.");


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