我有在jquery validation Normalizer
問題的陣列驗證無法正常工作,應該驗證以下模式jQuery驗證正規化上<code>array of input</code></p> <p>問題的投入
i.e. (example.com) or (http://example.com) or (http://www.example.com)
這裏的代碼
Html
<form name="xyz">
...
<input type="url" name="url[]">
<input type="url" name="url[]">
<input type="url" name="url[]">
<input type="url" name="url[]">
...
</form>
的Javascript
$('form').validate({
rules: {
'url[]': {
url: true,
normalizer: function(el) {
var url = el.value;
// Check if it doesn't start with http:// or https:// or ftp://
if (url && url.substr(0, 7) !== "http://"
&& url.substr(0, 8) !== "https://") {
// then prefix with http://
url = "http://" + url;
}
// Return the new url
return url;
}
}
}
});
作爲一個側面說明,我建議使用'toLowerCase()'比較子之前。 'Https://'與'https://'不一樣,所以你可以用'http:// https:// google.com'這樣的鏈接來結束。 – Santi
@Santi這不是問題,或者我做小寫或大寫,你可以看看這個問題我得到了什麼 –