Extjs 前端校验的一些方式总结

1)、文本框:

输入不能为空:设置配置项allowBlank:false;

输入最大长度:maxLength:Number ;

输入最小长度:minLength:Number ;

不能输入负数:allowNegative:false;

不能输入小数:allowDecimals:false;

规定输入数字范围:minValue和maxValue;

2)、借助vtype:

只能输入英文字母:vtype:’alpha’;

只能输入英文字母和数字:vtype:’alphanum’;

电子邮箱: vtype:’email’;

网址:vtype:’url’;

3)、生日验证:

Ext.apply(Ext.form.VTypes,{

           birthdayCheck:function(val,field){

              if(field.confirmTo){

                  varcheckBirthday = setForm.getForm().findField('identityNum').getValue();

                  var strBirthday= checkBirthday.substring(6,14);

                  var t =val.split('-');

                  var year =t[0];

                  var month =t[1];

                  var day = t[2];

                  var time = year+ month + day;

                  return(strBirthday == time);

              }

              return true;

           }

       });

{

Items:[{xtype:'textfield'

           ,id:'identityId'

           ,fieldLabel:'身份证号'

           ,name:'identityNum'

           ,anchor:'95%'

       },{

           xtype:'datefield'

           ,fieldLabel:'生日'

           ,id:'birthdayId'

           ,name:'birthday'

           ,vtype:'birthdayCheck'

           ,vtypeText:'生日填写错误'

           ,confirmTo:'identityId'

           ,format:'Y-m-d'

           ,anchor:'95%'

           }]

4)、密码验证:

//添加自定义的password验证函数

Ext.apply(Ext.form.VTypes,{

    password:function(val,field){//value指文本框的值,field指文本框组件

       if(field.confirmTo){

           varpwd=Ext.get(field.confirmTo);//confirmTo指自定义的配置参数,一般用来保存另外的组件的id值

           return(val==pwd.getValue());

       }

       return true;

    }

});

       items:[{

              id:"pass1",

              fieldLabel:'密码',

              inputType:'password'

       },{fieldLabel:'确认密码',

           id:"pass2",

           inputType:'password',

           vtype:'password',

           vtypeText:'两次密码不一致',

           confirmTo:"pass1"

       }]               

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值