1. #1
    Ext User
    Join Date
    Jan 2009
    Posts
    8
    Vote Rating
    0
    gauravk is on a distinguished road

      0  

    Default regex not working properly

    regex not working properly


    I want to validate a text field using only a single regex which validates the text as a Number which is 0- 4 digits in length.

    new Ext.form.TextField(
    {
    id: 'T1',
    regex: /[0-9]\{0,4\}/,
    regexText: 'Should be Number between 0 - 9999',
    validator:function(value){
    re = new RegExp('/[0-9]\{0,4\}/');
    return re.test(value);
    }
    });
    Last edited by mystix; 8 Jun 2009 at 3:18 AM. Reason: moved to 2.x Help from Open Discussion

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    new RegExp('/[0-9]\{0,4\}/') ?

    Read a Javascript book or online tutorial. That's wrong.

    The regex config you specify will check that the input contains a string of digits between 0 and 4 characters long.

  3. #3
    Ext User
    Join Date
    Jan 2009
    Posts
    8
    Vote Rating
    0
    gauravk is on a distinguished road

      0  

    Default


    Yes thats what I want to check "input contains a string of digits between 0 and 4 characters long"

    but the expression is not doing so, Please let me know how to achieve this

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    It will always contain a string of digits between 0 and 4 characters long. Think about it.

  5. #5
    Sencha User conorarmstrong's Avatar
    Join Date
    Mar 2008
    Location
    Northern Ireland
    Posts
    224
    Vote Rating
    2
    conorarmstrong is on a distinguished road

      0  

    Default


    just to be clear and to confirm @Animal's post, the string 'ABCD' contains a string of numbers of length 0 (in five places).
    ------------------------------------------
    Conor Armstrong
    tw: @evathedog
    web: rockstown.com

    Ext.ux.form.AutoCombo
    Ext.ux.SimpleIFrame
    Ext.ux.form.ToolFieldSet

    Knowledge is realising that the street is one-way, wisdom is looking both directions anyway.

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Yes, "contains" !== "is a"

    Those two conditions require different regular expression coding. You are on track, but not there.

Thread Participants: 2