Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict the input characters in textfield / numberfield using regular expression?

Tags:

I use numberField in ExtJS Form and want to enter only positive numbers, in range of 0-99 and it should accept only 2 characters (and not more than 2).

{
    xtype:"textfield",
    allowNegative: false,
    allowDecimals: false,
    minValue: 0,
    maxValue: 99,
    maxLength: 2
}

gives an error in above code but it is accepting more then 2 characters.

I also tried below but issue is same:

{
    xtype:"textfield",
    regex: /^\d{0,2}$/,
    regexText: "<b>Error</b></br>Invalid Number entered.",
    validator: function(v) {
        return /^\d{0,2}$/.test(v)?true:"Invalid Number";
    }
}

How to restrict to input more then 2 characters?