Ext.form.field.VTypes
This is a singleton object which contains a set of commonly used field validation functions. The validations provided are basic and intended to be easily customizable and extended.
To add custom VTypes specify the vtype
validation test function, and optionally specify any corresponding error text to display and any keystroke filtering mask to apply
{ xtype: 'textfield', name: 'foldername', fieldLabel: '目录名称', allowBlank:false, vtype: 'words', wordsLength:100, regex:/^[^\\\/:\*\?|<>"]+$/, regexText:'非法字符\\ | /:*?\"<>', value: '' }
checkWords: function(){ Ext.apply(Ext.form.field.VTypes, { words: function(val, field) { var len = field.wordsLength;//获取field中定义的字符长度 val = val.replace(/[\u4e00-\u9fa5]/g,'**');//替换中文为两个* if(val.length == len){ this.wordsText = "该输入项的最大长度是 "+len+" 个字符" //设置验证不通过时提示语 } return val.length < len; //true为验证通过,false为不通过 } }); }
在引入form之前调用checkWords()即可