开发者

Using regular expression in Ext Js VType

开发者 https://www.devze.com 2023-02-10 02:08 出处:网络
I have a regular expression for checking numbers and allowing \"-\" (Hyphen) Text Field. var regex = /^\\d+-\\d{1,2}$/;//Checks \"digits-digit(s,1 or 2)\"

I have a regular expression for checking numbers and allowing "-" (Hyphen) Text Field.

var regex = /^\d+-\d{1,2}$/;  //Checks "digits-digit(s,1 or 2)"

This works ok for regular HTML text field. But if I want a Ext Js TextField I have to do the below code

Ext js TextField and called a VType

var <portlet:namespace/>issueNoField = new Ext.form.TextField({
     fieldLabel: 'Issue No',
     width: 120,
     valueField:'IssNo',
     vtype: 'hyphen'
 });

Ext.apply(Ext.form.VTypes, {
                hyphenText : "Only numbers and hyphen.",
                hyphenMask:/[0-9-]/,
                hyphenRe: /^\d+-\d{1,2}$/,  //This is the check
                hyph开发者_如何学Goen:function(x){return this.hyphenRe.test(x);}   //Am i missing a numericHyMask: here ??
            });     

      Is hyphenRe: /^\d+-\d{1,2}$/, is correct or
      is hyphenRe: /^\d+-[\d{1,2}]$/, is correct as I want 1 or 2 digits after '-'

Please help me change my VTypes to work properly and do that regex check.


Works fine for me. Is the validation itself not working (the field doesn't get underlined when you type invalid stuff in it) or are you missing the error-tooltip? On the latter case add somewhere in your code:

Ext.QuickTips.init();

Otherwise the tooltips wont appear.

0

精彩评论

暂无评论...
验证码 换一张
取 消