//覆写Ext.form.TextField里面的属性
Ext.apply(Ext.form.TextField.prototype,{
//输入是否校验中文
validateCnLength : true, //false,
//是否去除两端空格
//trimValue : true ,
//值校验
validateValue : function(value){
if(value.length < 1 || value === this.emptyText){ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
//如果validateCnLength为真,验证中英混合字符串,否则验证纯英字符串
if( this.validateCnLength ? this.cnLength(value) > this.maxLength : value.length > this.maxLength ){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value, this)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
if(typeof this.validator == "function"){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
return true;
},
//添加获取中英混合字符串长度
cnLength : function (str) {
var totallength=0;
for (var i=0;i<str.length;i++)
{
var intCode=str.charCodeAt(i);
if (intCode >= 0 && intCode <= 128 ) {
totallength=totallength+1;//非中文单个字符长度加1
}else {
totallength=totallength+2;//中文字符长度则加2
}
}
return totallength;
},
//不能输入空格
validator : function(text) {
if (this.allowBlank == false && Ext.util.Format.trim(text).length == 0){
return false;
}else{
return true;
}
}
})
Ext.apply(Ext.form.TextField.prototype,{
//输入是否校验中文
validateCnLength : true, //false,
//是否去除两端空格
//trimValue : true ,
//值校验
validateValue : function(value){
if(value.length < 1 || value === this.emptyText){ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
//如果validateCnLength为真,验证中英混合字符串,否则验证纯英字符串
if( this.validateCnLength ? this.cnLength(value) > this.maxLength : value.length > this.maxLength ){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value, this)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
if(typeof this.validator == "function"){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
return true;
},
//添加获取中英混合字符串长度
cnLength : function (str) {
var totallength=0;
for (var i=0;i<str.length;i++)
{
var intCode=str.charCodeAt(i);
if (intCode >= 0 && intCode <= 128 ) {
totallength=totallength+1;//非中文单个字符长度加1
}else {
totallength=totallength+2;//中文字符长度则加2
}
}
return totallength;
},
//不能输入空格
validator : function(text) {
if (this.allowBlank == false && Ext.util.Format.trim(text).length == 0){
return false;
}else{
return true;
}
}
})