Extjs自定义form表单验证
2011-08-25 15:31
1026 查看
Ext4.0 已经提供了用于扩展表单验证的单例类:
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
test function, and optionally specify any corresponding error text to display and any keystroke filtering mask to apply
现在我们要做一个text的验证:要求是:输入内容不能超过100个字符,一个汉字抵两个字符,也就是不能超过50个汉字100个字母。
配置项:
在引入form之前调用
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
vtypevalidation
test function, and optionally specify any corresponding error text to display and any keystroke filtering mask to apply
现在我们要做一个text的验证:要求是:输入内容不能超过100个字符,一个汉字抵两个字符,也就是不能超过50个汉字100个字母。
配置项:
{ 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()即可
相关文章推荐
- Extjs form validate 表单验证 代码 总结 心得
- form表单中input的required属性和自定义验证方式冲突的解决策略
- Laravel中使用FormRequest进行表单验证及对验证异常进行自定义处理
- Extjs form validate 表单验证总结
- 使用Django的ModelForm对表单进行自动验证(可自定义验证规则)
- ExtJS学习笔记(1)-表单验证,Ext.FormPanel
- ExtJS中表单验证使用自定义vtype(两次输入密码重复)示例
- extjs 自定义表单验证函数
- Form表单提交、自定义验证规则(validate插件)
- ExtJS中表单验证使用自定义vtype示例
- ExtJs 自定义表单验证
- coolite Form表单验证之自定义验证
- ExtJs 备忘录(3)—— Form表单(三) [ 数据验证 ]
- easyui form表单提交自定义验证数据是否已存在
- Extjs form validate 表单验证
- Django(5) session登录注销、csrf及中间件自定义、django Form表单验证(非常好用)
- drupal7之学习在已存在的form表单中增加自定义验证(Learn how to add custom validation to an existing Drupal form)
- tornado之自定义form表单验证
- extJs form表单textfield中包含中文的长度验证问题
- ExtJs 备忘录(3)—— Form表单(三) [ 数据验证 ]