EXTJS 表单验证方法大全

EXTJS前台表单方法验证一览
Ext.onReady(function(){
    var form = new Ext.form.FormPanel({
    labelAlign: 'right',
    labelWidth: 250
});
form.add(new Ext.form.TextField({
    fieldLabel: '不能为空',
    allowBlank: false
}));
form.add(new Ext.form.TextField({
    fieldLabel: '最小5,最大10',
    name: 'text',
    maxLength: 10,
    minLength: 5
}));
form.add(new Ext.form.TextField({
    fieldLabel: 'E-mail',
    name: 'text',
    vtype: 'email'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '只能英文',
    name: 'text',
    vtype: 'alpha'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '只能字母和数字',
    name: 'text',
    vtype: 'alphanum'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '只能网址',
    name: 'text',
    vtype: 'url'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '只能汉字',
    name: 'text',
    regex: /^[\u4E00-\u9FA5]+$/,
    regexText: '只能输入汉字'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '手机号码必须13开头,后面跟9位数字!',
    name: 'text',
    regex: /^13[\d]{9}$/,
    regexText: '手机号码必须13开头,后面跟9位数字!'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '电话号码必须如:0xx-1234344',
    name: 'text',
    regex: /^0(\d{2}|\d{3})\-(\d{7}|\d{8})$/,
    regexText: '电话号码必须如:0xx-1234344'
}));
form.add(new Ext.form.TextField({
    fieldLabel: '只能IP地址',
    name: 'text',
    regex: /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,
    regexText: '只能输入IP地址'
}));
form.render("form");

你可能感兴趣的:(EXT,JS)