《精通ExtJS》這本書里說可以自定義表單驗證。 自定義的vtype可以放在一個.js的文件里。
這是vtypes.js里的代碼:
Ext.apply(Ext.form.field.VTypes, {
customPass: function(val, field) {
return /^((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})/.test(val);
},
customPassText: 'Not a valid password. Length must be at least 6 characters and maximum of 20. Password must contain one digit, one letter lowercase, one letter uppercase, one special symbol @#$% and between 6 and 20 characters.'
});
這段代碼放在controller里是沒有問題的。 放在vtypes.js里如何使用呢?
光陰似箭催人老,日月如移越少年。
這個我寫過。在vtypes.js直接放你上面的代碼,在要用到的view文件中添加requires配置,把vtypes.js文件引入,然后就可以正常用了。