1.驗證輸入框長度:一個漢字等於兩個字符問題
validator:function(){
var str = Ext.util.Format.trim(news.getValue());
var size = 0;
for(var i=0;i<str.length;i++){
var code = str.charCodeAt(i);
if(code > 255){
size += 2;
}else{
size += 1;
}
if(size > 30){
news.invalidText = '長度不能超過30!';
news.focus();
return false;
}else{
return true;
}
}
}
2.只能輸入中文、字母、數字、英文逗號、英文句號!
regex:/^([\u0391-\uFFE5]|[a-zA-Z]|\d[-,._])*$/,
regexText: '只能輸入中文、字母、數字、英文逗號、英文句號',
regex: /^([\u0391-\uFFE5]|[a-zA-Z]|\d|_)*$
regexText: 只能輸入中文字母數字下劃線
3.鼠標提醒還可以輸入多少個字:
enableKeyEvents: true,
listeners:{
"keyup": function(cur,evt){
var curLen = cur.getValue().length;
if(curLen <= 500){
news.viewTi = '你還可以輸入:'+(500-curLen)+'個字';
Ext.get('notic').dom.innerHTML = news.viewTi;
}else{
news.viewTi = '<font color="red" style="margin-right:-70px">字數超過範圍 請酌情刪減</font>';
Ext.get('notic').dom.innerHTML = news.viewTi;
}
}
}
需在panel裏面加上->html:<div id='notic' style='color:#0000FF;text-align:center;margin-left:-55px'</div>
var startDate = new Ext.form.DateField({ id : 'startDate', style : 'margin-bottom: 5px;', fieldLabel : '開始日期', format : 'Y-m-d', allowBlank : false, blankText : '不能爲空', editable : false, listeners:{"blur":function(){ Ext.getCmp('endDate').setMinValue(Ext.get('startDate').getValue()); }} }); var startTime = new Ext.form.TimeField({ id : 'startTime', style : 'margin-bottom: 5px;', fieldLabel : '開始時間', allowBlank : false, editable : false, blankText : '不能爲空', format : 'G:i' }); var endDate = new Ext.form.DateField({ id : 'endTime1', style : 'margin-bottom: 5px;', fieldLabel : '結束日期', allowBlank : false, blankText : '不能爲空', format : 'Y-m-d ', editable : false, listeners:{"blur":function(){ Ext.getCmp('startDate').setMinValue(Ext.get('endDate').getValue()); }} }); var endTime = new Ext.form.TimeField({ id : 'endTime2', style : 'margin-bottom: 5px;', fieldLabel : '結束時間', allowBlank : false, blankText : '不能爲空', editable : false, format : 'G:i' });
regex: /^([a-zA-Z]|\d|_)*$,
regex:‘只能輸入數字字母下劃線‘
regex : /^([\u0391-\uFFE5]|[ ]|[a-zA-Z]|\d|_)*$/,
regexText : '' 只能輸入中文字母數字空格下劃線“,
兩次密碼一致性檢查:
{ columnWidth : 0.5, layout : 'form', defaultType : 'textfield', items : [ { fieldLabel : '' + getResource('resourceParam870') + '', inputType : 'password', name : 'newpassword1', id : 'newpassword1', regex : /^([\u0391-\uFFE5]|[a-zA-Z]|\d|_)*$/, regexText : '' + getResource('resourceParam863') + '', width : 175, minLength : 1, maxLength : 20, allowBlank : false, value : 123456, anchor : '95%', listeners : { 'blur' : function() { if ("" != Ext.getCmp('newpassword2').getValue()) { Ext.getCmp('newpassword2').validate(); } } }} ] },{ columnWidth : 0.5, layout : 'form', defaultType : 'textfield', items : [ { fieldLabel : '' + getResource('resourceParam867') + '', inputType : 'password', name : 'newpassword2', id : 'newpassword2', regex : /^([\u0391-\uFFE5]|[a-zA-Z]|\d|_)*$/, regexText : '' + getResource('resourceParam863') + '', width : 175, minLength : 1, maxLength : 20, allowBlank : false, value : 123456, invalidText : '' + getResource('resourceParam871') + '', anchor : '95%', validator : function() { return (Ext.getCmp('newpassword2').getValue() == Ext.getCmp('newpassword1').getValue()); } } ] }