标签:
http://blog.sina.com.cn/s/blog_944b24ef0101epr5.html
$.hx = {};
$.hx.data = {
isEmpty: function (value) {
var item = $.trim(value);
return item.length === 0;
},
isNumber: function (value) {
return !isNaN(item);
}
};
$.hx.regex = {
expression: {
email: /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/, //e.g. admin@pailv.com
password: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{7,20}$/,//e.g. admin888
cabin: /^[a-zA-Z]{1}$/,
cabins: /^([a-zA-Z]{1}\/){1,30}$/,
airline: /^(([A-Za-z]{2})|([A-Za-z]\d)|(\d[A-Za-z])){1}$/,
mainAirportCode: /^([a-zA-Z]{3}\/){1,10}$/,//e.g. pvg/PVG/pVg/
airportCode: /^([a-zA-Z]{3}\/){1,300}$/,//e.g. pvg/PVG/pVg/ 最大改成了300个机场,原先的一些最大数在控件中使用maxlength做了限制 update by wss on20150511
unsignedInteger: /^\d+$/,
integer: /^(-){0,1}\d+$/,
flightNo: /^((\d{1,4}-\d{1,4}\/)|(\d{1,4}\/)){0,10}$/, //e.g. 1/2/6666-8888/9000-9999/
date: /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/,
currencyCode: /^[a-zA-Z]{3}$/,
double: /^(-)?\d+(\.\d+)?$/,
decimal: /^((\d|[1-9]\d+)(\.\d{1,2}){0,1}){1}$/,
cityCode: /^[A-Za-z]{3}(\/{1}[A-Za-z]{3}){0,}?$/,
invoiceAirline: /^[0-9A-Za-z]{2}(\/[0-9A-Za-z]{2}){0,}?$/,
CabinLevel: /^[A-Za-z]{1}(\/[A-Za-z]{1}){0,}?$/,
Airport: /^[a-zA-Z]{3}$/,
airlines: /^((([A-Za-z]{2})|([A-Za-z]\d)|(\d[A-Za-z]))\/){1,100}$/
},
matchReg: function (source, reg) {
source.match(reg);
},
matchEmail: function (source) {
return source.match(this.expression.email);
},
matchPassword: function (source) {
return source.match(this.expression.password);
},
matchCabin: function (source) {
return source.match(this.expression.cabin);
},
matchCabins: function (source, autoAppend) {
var result = source;
if (autoAppend && result.lastIndexOf("/") != result.length - 1) {
result = result + "/";
}
return result.match(this.expression.cabins);
},
matchAirline: function (source) {
return source.match(this.expression.airline);
},
matchMainAirportCode: function (source, autoAppend) {
var result = source;
if (autoAppend && result.lastIndexOf("/") != result.length - 1) {
result = result + "/";
}
return result.match(this.expression.mainAirportCode);
},
matchAirportCode: function (source, autoAppend) {
var result = source;
if (autoAppend && result.lastIndexOf("/") != result.length - 1) {
result = result + "/";
}
return result.match(this.expression.airportCode);
},
matchUnsignedInteger: function (source) {
return source.match(this.expression.unsignedInteger);
},
matchFlightNo: function (source, autoAppend) {
var result = source;
if (autoAppend && result.lastIndexOf("/") != result.length - 1) {
result = result + "/";
}
return result.match(this.expression.flightNo);
},
matchDate: function (source) {
return source.match(this.expression.date);
},
matchInteger: function (source) {
return source.match(this.expression.integer);
},
matchIntegerRange: function (source, min, max) {
if (!source.match(this.expression.integer)) {
return false;
}
if (Number(source) < min || Number(source) > max) {
return false;
}
return true;
},
matchCurrencyCode: function (source) {
return source.match(this.expression.currencyCode);
},
matchDouble: function (source) {
return source.match(this.expression.double);
},
matchDecimal: function (source) {
return source.match(this.expression.decimal);
},
matchCityCode: function (source) {
return source.match(this.expression.cityCode);
},
matchInvoiceAirline: function (source) {
return source.match(this.expression.invoiceAirline);
},
matchCabinLevel: function (source) {
return source.match(this.expression.CabinLevel);
},
matchAirport: function (source) {
return source.match(this.expression.Airport);
},
matchAirlines: function (source) {
var result = source;
if (result.lastIndexOf("/") != result.length - 1) {
result = result + "/";
}
return result.match(this.expression.airlines);
}
};
$.hx.style = {
addError: function (o) {
o.addClass("error");
o.focus();
},
removeError: function (o) {
o.removeClass("error");
},
addSubmitting: function (o) {
}
};
$.hx.compare = {
date: function (start, end) {
var startTime = new Date(start.replace(/-/gi, "/"));
var endTime = new Date(end.replace(/-/gi, "/"));
if (endTime < startTime) {
return false;
}
return true;
}
};
标签:
原文地址:http://www.cnblogs.com/xiaocandou/p/4560377.html