/**
* jquery validation plugin 1.9.0
*
* http://bassistance.de/jquery-plugins/jquery-plugin-validation/
* http://docs.jquery.com/plugins/validation
*
* copyright (c) 2006 - 2011 j枚rn zaefferer
*
* dual licensed under the mit and gpl licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function() {
function striphtml(value) {
// remove html tags and space chars
return value.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' ')
// remove numbers and punctuation
.replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g,'');
}
jquery.validator.addmethod("password", function( value, element ) {
var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
if (!result) {
//element.value = "";
var validator = this;
settimeout(function() {
validator.blockfocuscleanup = true;
element.focus();
validator.blockfocuscleanup = false;
}, 1);
}
return result;
}, "鍖呭惈鏁板瓧鍜屽瓧姣嶄笖涓嶅皯浜?浣嶆暟");
jquery.validator.addmethod("maxwords", function(value, element, params) {
return this.optional(element) || striphtml(value).match(/\b\w+\b/g).length < params;
}, jquery.validator.format("please enter {0} words or less."));
jquery.validator.addmethod("minwords", function(value, element, params) {
return this.optional(element) || striphtml(value).match(/\b\w+\b/g).length >= params;
}, jquery.validator.format("please enter at least {0} words."));
jquery.validator.addmethod("rangewords", function(value, element, params) {
return this.optional(element) || striphtml(value).match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1];
}, jquery.validator.format("please enter between {0} and {1} words."));
})();
jquery.validator.addmethod("letterswithbasicpunc", function(value, element) {
return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value);
}, "letters or punctuation only please");
jquery.validator.addmethod("alphanumeric", function(value, element) {
return this.optional(element) || /^\w+$/i.test(value);
}, "letters, numbers, spaces or underscores only please");
jquery.validator.addmethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z]+$/i.test(value);
}, "letters only please");
jquery.validator.addmethod("nowhitespace", function(value, element) {
return this.optional(element) || /^\s+$/i.test(value);
}, "no white space please");
jquery.validator.addmethod("ziprange", function(value, element) {
return this.optional(element) || /^90[2-5]\d\{2}-\d{4}$/.test(value);
}, "your zip-code must be in the range 902xx-xxxx to 905-xx-xxxx");
jquery.validator.addmethod("integer", function(value, element) {
return this.optional(element) || /^-?\d+$/.test(value);
}, "a positive or negative non-decimal number please");
/**
* return true, if the value is a valid vehicle identification number (vin).
*
* works with all kind of text inputs.
*
* @example
* @desc declares a required input element whose value must be a valid vehicle identification number.
*
* @name jquery.validator.methods.vinus
* @type boolean
* @cat plugins/validate/methods
*/
jquery.validator.addmethod(
"vinus",
function(v){
if (v.length != 17)
return false;
var i, n, d, f, cd, cdv;
var ll = ["a","b","c","d","e","f","g","h","j","k","l","m","n","p","r","s","t","u","v","w","x","y","z"];
var vl = [1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9];
var fl = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];
var rs = 0;
for(i = 0; i < 17; i++){
f = fl[i];
d = v.slice(i,i+1);
if(i == 8){
cdv = d;
}
if(!isnan(d)){
d *= f;
}
else{
for(n = 0; n < ll.length; n++){
if(d.touppercase() === ll[n]){
d = vl[n];
d *= f;
if(isnan(cdv) && n == 8){
cdv = ll[n];
}
break;
}
}
}
rs += d;
}
cd = rs % 11;
if(cd == 10){cd = "x";}
if(cd == cdv){return true;}
return false;
},
"the specified vehicle identification number (vin) is invalid."
);
/**
* return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
*
* @example jquery.validator.methods.date("01/01/1900")
* @result true
*
* @example jquery.validator.methods.date("01/13/1990")
* @result false
*
* @example jquery.validator.methods.date("01.01.1900")
* @result false
*
* @example
* @desc declares an optional input element whose value must be a valid date.
*
* @name jquery.validator.methods.dateita
* @type boolean
* @cat plugins/validate/methods
*/
jquery.validator.addmethod(
"dateita",
function(value, element) {
var check = false;
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
if( re.test(value)){
var adata = value.split('/');
var gg = parseint(adata[0],10);
var mm = parseint(adata[1],10);
var aaaa = parseint(adata[2],10);
var xdata = new date(aaaa,mm-1,gg);
if ( ( xdata.getfullyear() == aaaa ) && ( xdata.getmonth () == mm - 1 ) && ( xdata.getdate() == gg ) )
check = true;
else
check = false;
} else
check = false;
return this.optional(element) || check;
},
"please enter a correct date"
);
jquery.validator.addmethod("datenl", function(value, element) {
return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
}, "vul hier een geldige datum in."
);
jquery.validator.addmethod("time", function(value, element) {
return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){0,2}$/.test(value);
}, "please enter a valid time, between 00:00 and 23:59");
jquery.validator.addmethod("time12h", function(value, element) {
return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [ap]m))$/i.test(value);
}, "please enter a valid time, between 00:00 am and 12:00 pm");
/**
* matches us phone number format
*
* where the area code may not start with 1 and the prefix may not start with 1
* allows '-' or ' ' as a separator and allows parens around area code
* some people may want to put a '1' in front of their number
*
* 1(212)-999-2345
* or
* 212 999 2344
* or
* 212-999-0983
*
* but not
* 111-123-5434
* and not
* 212 123 4567
*/
jquery.validator.addmethod("phoneus", function(phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "please specify a valid phone number");
jquery.validator.addmethod('phoneuk', function(phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/);
}, 'please specify a valid phone number');
jquery.validator.addmethod('mobileuk', function(phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
}, 'please specify a valid mobile number');
// todo check if value starts with <, otherwise don't try stripping anything
jquery.validator.addmethod("strippedminlength", function(value, element, param) {
return jquery(value).text().length >= param;
}, jquery.validator.format("please enter at least {0} characters"));
// same as email, but tld is optional
jquery.validator.addmethod("email2", function(value, element, param) {
return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)*(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?$/i.test(value);
}, jquery.validator.messages.email);
// same as url, but tld is optional
jquery.validator.addmethod("url2", function(value, element, param) {
return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)*(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\ue000-\uf8ff]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
}, jquery.validator.messages.url);
// 鐧诲綍鍚?
jquery.validator.addmethod("strusername", function(value, element) {
return this.optional(element) || /^\w+$/.test(value);
}, "璐︽埛鍚嶅寘鎷嫳鏂囧瓧姣嶃€佹暟瀛楀拰涓嬪垝绾?);
// 瀛楃楠岃瘉
jquery.validator.addmethod("stringcheck", function(value, element) {
return this.optional(element) || /^[\u0391-\uffe5\w]+$/.test(value);
}, "鍙兘鍖呮嫭涓枃瀛椼€佽嫳鏂囧瓧姣嶃€佹暟瀛楀拰涓嬪垝绾?);
// 涓枃瀛椾袱涓瓧鑺?
jquery.validator.addmethod("byterangelength", function(value, element, param) {
var length = value.length;
for(var i = 0; i < value.length; i++){
if(value.charcodeat(i) > 127){
length++;
}
}
return this.optional(element) || ( length >= param[0] && length <= param[1] );
}, "璇风‘淇濊緭鍏ョ殑鍊煎湪3-15涓瓧鑺備箣闂?涓€涓腑鏂囧瓧绠?涓瓧鑺?");
// 韬唤璇佸彿鐮侀獙璇?
jquery.validator.addmethod("isidcardno", function(value, element) {
return this.optional(element) || idcardnoutil.checkidcardno(value);
}, "璇锋纭緭鍏ユ偍鐨勮韩浠借瘉鍙风爜");
//鎶ょ収缂栧彿楠岃瘉
jquery.validator.addmethod("passport", function(value, element) {
return this.optional(element) || checknumber(value);
}, "璇锋纭緭鍏ユ偍鐨勬姢鐓х紪鍙?);
// 鎵嬫満鍙风爜楠岃瘉
jquery.validator.addmethod("ismobile", function(value, element) {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
return this.optional(element) || (length == 11 && mobile.test(value));
}, "璇锋纭~鍐欐偍鐨勬墜鏈哄彿鐮?);
// 鐢佃瘽鍙风爜楠岃瘉
jquery.validator.addmethod("istel", function(value, element) {
var tel = /^\d{3,4}-?\d{7,9}$/; //鐢佃瘽鍙风爜鏍煎紡010-12345678
return this.optional(element) || (tel.test(value));
}, "璇锋纭~鍐欐偍鐨勭數璇濆彿鐮?);
// 鑱旂郴鐢佃瘽(鎵嬫満/鐢佃瘽鐨嗗彲)楠岃瘉
jquery.validator.addmethod("isphone", function(value,element) {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var tel = /^\d{3,4}-?\d{7,9}$/;
return this.optional(element) || (tel.test(value) || mobile.test(value));
}, "璇锋纭~鍐欐偍鐨勮仈绯荤數璇?);
// 閭斂缂栫爜楠岃瘉
jquery.validator.addmethod("iszipcode", function(value, element) {
var zc = /^[0-9]{6}$/;
return this.optional(element) || (zc.test(value));
}, "璇锋纭~鍐欐偍鐨勯偖鏀跨紪鐮?);
// 鍩熷悕
jquery.validator.addmethod("isdomain", function(value, element) {
var domain = /^([\w.]+)$/;
return this.optional(element) || (domain.test(value));
}, "璇锋纭~鍐欐偍鐨勪富鍩熷悕");
// notice: modified version of castle.components.validator.creditcardvalidator
// redistributed under the the apache license 2.0 at http://www.apache.org/licenses/license-2.0
// valid types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
jquery.validator.addmethod("creditcardtypes", function(value, element, param) {
if (/[^0-9-]+/.test(value))
return false;
value = value.replace(/\d/g, "");
var validtypes = 0x0000;
if (param.mastercard)
validtypes |= 0x0001;
if (param.visa)
validtypes |= 0x0002;
if (param.amex)
validtypes |= 0x0004;
if (param.dinersclub)
validtypes |= 0x0008;
if (param.enroute)
validtypes |= 0x0010;
if (param.discover)
validtypes |= 0x0020;
if (param.jcb)
validtypes |= 0x0040;
if (param.unknown)
validtypes |= 0x0080;
if (param.all)
validtypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
if (validtypes & 0x0001 && /^(51|52|53|54|55)/.test(value)) { //mastercard
return value.length == 16;
}
if (validtypes & 0x0002 && /^(4)/.test(value)) { //visa
return value.length == 16;
}
if (validtypes & 0x0004 && /^(34|37)/.test(value)) { //amex
return value.length == 15;
}
if (validtypes & 0x0008 && /^(300|301|302|303|304|305|36|38)/.test(value)) { //dinersclub
return value.length == 14;
}
if (validtypes & 0x0010 && /^(2014|2149)/.test(value)) { //enroute
return value.length == 15;
}
if (validtypes & 0x0020 && /^(6011)/.test(value)) { //discover
return value.length == 16;
}
if (validtypes & 0x0040 && /^(3)/.test(value)) { //jcb
return value.length == 16;
}
if (validtypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
return value.length == 15;
}
if (validtypes & 0x0080) { //unknown
return true;
}
return false;
}, "please enter a valid credit card number.");
jquery.validator.addmethod("ipv4", function(value, element, param) {
return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i.test(value);
}, "please enter a valid ip v4 address.");
jquery.validator.addmethod("ipv6", function(value, element, param) {
return this.optional(element) || /^((([0-9a-fa-f]{1,4}:){7}[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){6}:[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){5}:([0-9a-fa-f]{1,4}:)?[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){4}:([0-9a-fa-f]{1,4}:){0,2}[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){3}:([0-9a-fa-f]{1,4}:){0,3}[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){2}:([0-9a-fa-f]{1,4}:){0,4}[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9a-fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9a-fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9a-fa-f]{1,4}::([0-9a-fa-f]{1,4}:){0,5}[0-9a-fa-f]{1,4})|(::([0-9a-fa-f]{1,4}:){0,6}[0-9a-fa-f]{1,4})|(([0-9a-fa-f]{1,4}:){1,7}:))$/i.test(value);
}, "please enter a valid ip v6 address.");
/**
* return true if the field value matches the given format regexp
*
* @example jquery.validator.methods.pattern("ar1004",element,/^ar\d{4}$/)
* @result true
*
* @example jquery.validator.methods.pattern("br1004",element,/^ar\d{4}$/)
* @result false
*
* @name jquery.validator.methods.pattern
* @type boolean
* @cat plugins/validate/methods
*/
jquery.validator.addmethod("pattern", function(value, element, param) {
return this.optional(element) || param.test(value);
}, "invalid format.");