Why am I getting an false return for this regular expression?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Gibbons

    Why am I getting an false return for this regular expression?

    var Foo = ValidateForNumb ("111", 3, 5, "Warning goes here")

    ------------------------

    function ValidateForNumb (strEntry, intMin, intMax, strWarning)
    {
    var blnOK = /^\d{intMin,intM ax}$/.test(strEntry) ;
    if ((blnOK == false) && (strEntry.lengt h > 0))
    {
    alert(strWarnin g);
    return false;
    }
    return strEntry;
    }

    ------------------------

    What's odd is that I when I use hard coded min and max, it comes back as
    true . . .

    ------------------------

    function ValidateForNumb (strEntry, intMin, intMax, strWarning)
    {
    var blnOK = /^\d{3,5}$/.test(strEntry) ;
    if ((blnOK == false) && (strEntry.lengt h > 0))
    {
    alert(strWarnin g);
    return false;
    }
    return strEntry;
    }

    ------------------------

    I can't imagine that javascript can't use the variable, am I doing something
    wrong here? What am I missing?

    Please contact me if you have any questions,

    Patrick Gibbons
    fnkleroi@hotmai l.com


  • Mark Szlazak

    #2
    Re: Why am I getting an false return for this regular expression?

    JavaScript regex literals are hard-coded. You'll have to dynamically
    build your pattern as a string and use it with

    new RegExp(pattern)



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    Working...