Regex doesn't work properly

Posted by oneofthelions on Stack Overflow See other posts from Stack Overflow or by oneofthelions
Published on 2011-02-14T07:24:00Z Indexed on 2011/02/14 7:25 UTC
Read the original article Hit count: 149

Filed under:
|
|
|
|

I am trying to implement a regular expression to allow only one or two digits after a hyphen '-' and it doesn't work properly. It allows as many digits as user types after '-'

Please suggest my ExtJS

Ext.apply(Ext.form.VTypes, {
  hyphenText: "Number and hyphen",
  hyphenMask: /[\d\-]/,
  hyphenRe: /^\d+-\d{1,2}$/,
  hyphen: function(v){
    return Ext.form.VTypes.hyphenRe.test(v);
  }
});

    //Input Field for Issue no
 var <portlet:namespace/>issueNoField = new Ext.form.TextField({
 fieldLabel: 'Issue No',
   width: 120,
   valueField:'IssNo',
   vtype: 'hyphen'

 });

This works only to the limit that it allows digits and -. But it also has to allow only 1 to 2 digits after - at most.

Is something wrong in my regex? hyphenRe: /^\d+-\d{1,2}$/,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex