I have a form running with jquery validate. The url methode they are using require http to be added to the url, and I want to allow users to submit url without http and or www. I used add methode:
jQuery.validator.addMethod("urlRegex", function(value, element) {
return this.optional(element) || /^(?:([a-z]+):(?:([a-z]*):)?\/\/)?(?:([^:@]*)(?::([^:@]*))?@)?((?:[a-z0-9_-]+\.)+[a-z]{2,}|localhost|(?:(?:[01]?\d\d?|2[0-4]\d|25[0-5])\.){3}(?:(?:[01]?\d\d?|2[0-4]\d|25[0-5])))(?::(\d+))?(?:([^:\?\#]+))?(?:\?([^\#]+))?(?:\#([^\s]+))?$/.test(value);
}, "PLEASE ENTER A VAILD WEBSITE ");
and under the rules I added the new method:
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
website: {
required: true,
urlRegex: true
},
}
But it's still require http:\ at the beginning of the url. I checked this regex at regex101.com and it matches with urls such as example.com so I'm not sure if the problem is with the regex or with something else.
Thanks.