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

Giganews Newsgroups
Subject: Why am I getting an false return for this regular expression?
Posted by:  Patrick Gibbons (fnkler…@hotmail.com)
Date: Sun, 27 Jul 2003

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

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

function ValidateForNumb(strEntry, intMin, intMax, strWarning)
{
    var blnOK = /^\d{intMin,intMax}$/.test(strEntry);
    if ((blnOK == false) && (strEntry.length > 0))
    {
        alert(strWarning);
        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.length > 0))
    {
        alert(strWarning);
        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
fnkler…@hotmail.com

Replies