var Validate = function(){}
Validate.prototype = {
// 验证字符串
testString: function(str) {
return str.replace(/^\s+|\s+$/g, "") != "";
},
// 验证整数
testIntegerNumber: function(num) {
if (!this.testString(num)) {
return false;
}
return /^[0-9]+$/.test(num);
},
// 验证浮点数
testDoubleNumber: function(num) {
if (!this.testString(num)) {
return false;
}
return /^\d+(\.)\d+$/.test(num);
},
// 验证日期(yyyy/MM/dd)
testDate: function(date) {
if (!this.testString(date)) {
return false;
}
var reg = /^[1-2]\d{3}\/(0?[1-9]|1[0-2])\/(0?[1-9]|[12][0-9]|3[0-1])$/;
return reg.test(date);
},
// 验证Email
testEmail: function(email) {
if (!this.testString(email)) {
return false;
}
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
return reg.test(email);
},
// 验证中文
testChinese: function(str) {
if (!this.testString(str)) {
return false;
}
return !/^[u4E00-u9FA5]+$/.test(str);
}
}
Validate.prototype = {
// 验证字符串
testString: function(str) {
return str.replace(/^\s+|\s+$/g, "") != "";
},
// 验证整数
testIntegerNumber: function(num) {
if (!this.testString(num)) {
return false;
}
return /^[0-9]+$/.test(num);
},
// 验证浮点数
testDoubleNumber: function(num) {
if (!this.testString(num)) {
return false;
}
return /^\d+(\.)\d+$/.test(num);
},
// 验证日期(yyyy/MM/dd)
testDate: function(date) {
if (!this.testString(date)) {
return false;
}
var reg = /^[1-2]\d{3}\/(0?[1-9]|1[0-2])\/(0?[1-9]|[12][0-9]|3[0-1])$/;
return reg.test(date);
},
// 验证Email
testEmail: function(email) {
if (!this.testString(email)) {
return false;
}
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
return reg.test(email);
},
// 验证中文
testChinese: function(str) {
if (!this.testString(str)) {
return false;
}
return !/^[u4E00-u9FA5]+$/.test(str);
}
}