我有檢查,如果警語都包含一個jQuery驗證的正則表達式:jQuery驗證的正則表達式:多個規則檢查,同場
$.validator.addMethod("regex", function(value, element, regexp) {
return this.optional(element) || regexp.test(value);
}, "You must include the required keyword phrase(s).");
如果我有多個短語來檢查,我與他們加入:
$("#text").rules("add", { regex: /phrase one/i });
$("#text").rules("add", { regex: /another phrase/i });
$("#text").rules("add", { regex: /test phrase/i });
我遇到的問題是,它只是檢查最後一句規則,如果「測試短語」包括,但有些則沒有意義,它會接受它。我需要它來檢查以確保包含所有短語。
我也想了錯誤信息,以便能夠以包括缺少的階段,例如,如果「另一個短語」缺失,錯誤將是:
You must include the required phrase: another phrase
THX
我想我會試試這個,因爲沒有更好的答案。謝謝 – Ricky 2010-12-09 18:24:09