Foros de discusión

Website Validation(URL)

thumbnail
kabir khan, modificado hace 11 años.

Website Validation(URL)

New Member Mensajes: 21 Fecha de incorporación: 15/02/13 Mensajes recientes
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 hace 11 años.

RE: Website Validation(URL)

Regular Member Mensajes: 234 Fecha de incorporación: 13/03/12 Mensajes recientes
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 hace 11 años.

RE: Website Validation(URL)

New Member Mensajes: 21 Fecha de incorporación: 15/02/13 Mensajes recientes
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 hace 11 años.

RE: Website Validation(URL)

Regular Member Mensajes: 234 Fecha de incorporación: 13/03/12 Mensajes recientes
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 hace 11 años.

RE: Website Validation(URL)

New Member Mensajes: 21 Fecha de incorporación: 15/02/13 Mensajes recientes
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