I can't make my custom url validation rule work.
I'm adding new rule:
jQuery.validator.addMethod("complete_url", function(val, elem) {
// if no url, don't do anything
return /((([A-Za-z]{3,9}:(?://)?)(?:[-;:&=+$,w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,w]+@)[A-Za-z0-9.-]+)((?:/[+~%/.w-_]*)???(?:[-+=&;%@.w_]*)#?(?:[w]*))?)/.test(val);
});
...
$("#new_website").validate({
rules: {
url: "complete_url",
'website[url]': {
url: true,
required: true}
}
});
but it returns me
invalid URL
I checked Regex here - http://www.rubular.com/. It is working, but failing it my custom validator.
What I'm doing wrong ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…