Ext.form.VTypes

1、为空验证的两个配置
allowBlank:false //false则不能为空,默认为true

blankText:string//当为空时的错误提示信息

items : [{
	fieldLabel : 'ENAME',
	name : 'emp.ename',
	allowBlank : false,
	blankText:"雇员姓名不能为空!"
}]

2、 用vtype格式的验证

        items: [{
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email',
               vtypeText:"不是有效的邮箱地址"
       }]
form验证中vtype的默认支持类型:
a.alpha //只能输入字母,无法输入其他(如数字,特殊符号等)
b.alphanum//只能输入字母和数字,无法输入其他
c.email//email验证,要求的格式是"[email protected]"
d.url//url格式验证,要求的格式是[url]http://www.langsin.com[/url]

对应的正则表达式:

  alpha = /^[a-zA-Z_]+$/,
    alphanum = /^[a-zA-Z0-9_]+$/,
    email = /^(\w+)([\-+.\'][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
    url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;


3、自定义验证

// custom Vtype for vtype:'time'
var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Ext.apply(Ext.form.VTypes, {
    // vtype validation function
    time: function(val, field) {
        return timeTest.test(val);
    },
    // vtype Text property: The error text to display when the validation function returns false
    timeText: 'Not a valid time. Must be in the format "12:34 PM".',
    // vtype Mask property: The keystroke filter mask
    timeMask: /[\d\s:amp]/i
});

Ext.form.VTypesPublic Properties

Property Defined By
alphaMask: RegExp
The keystroke filter mask to be applied on alpha input. Defaults to: /[a-z_]/i
VTypes
alphanumMask: RegExp
The keystroke filter mask to be applied on alphanumeric input. Defaults to: /[a-z0-9_]/i
VTypes


你可能感兴趣的:(form)