1、为空验证的两个配置
allowBlank:false //false则不能为空,默认为true
2、 用vtype格式的验证
a.alpha //只能输入字母,无法输入其他(如数字,特殊符号等)
b.alphanum//只能输入字母和数字,无法输入其他
c.email//email验证,要求的格式是"langsin@gmail.com"
d.url//url格式验证,要求的格式是[url]http://www.langsin.com[/url]
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验证,要求的格式是"langsin@gmail.com"
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;
// 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.VTypes Public Properties
Property | Defined By | |
---|---|---|
alphaMask : RegExp
The keystroke filter mask to be applied on alpha input. Defaults to:
/[a-z_]/i
| VTypes | |
alphaText : String
The error text to display when the alpha validation function returns false. Defaults to:
'This field should only contain letters and _'
| VTypes | |
alphanumMask : RegExp
The keystroke filter mask to be applied on alphanumeric input. Defaults to:
/[a-z0-9_]/i
| VTypes | |
alphanumText : String
The error text to display when the alphanumeric validation function returns false. Defaults to:
'This field should only contain letters, numbers and _'
| VTypes | |
emailMask : RegExp
The keystroke filter mask to be applied on email input. See the
email method for information about more complex email validation. Defaults to:
/[a-z0-9_\.\-\+\'@]/i
| VTypes | |
emailText : String
The error text to display when the email validation function returns false. Defaults to:
'This field should be an e-mail address in the format "user@example.com"'
| VTypes | |
urlText : String
The error text to display when the url validation function returns false. Defaults to:
'This field should be a URL in the format "http:/'+'/www.example.com"'
| VTypes |