views:

64

answers:

3

Hi everyone,

I am trying to incorporate a regular expression i have used in the past in a different manner into some validtation checking through javascript.

The following is my script:

    var regOrderNo = new RegExp("\d{6}");
    var order_no = $("input[name='txtordernumber']").val();
    alert(regOrderNo.test(order_no));

Why would this not come back with true if the txtordernumber text box value was a six digit number or more?

Thanks in advance, Billy

A: 

Insert an extra "\" in your regexp.

Cleiton
This was the solution. thank you.
Billy Logan
+1  A: 

You need to escape your backslash. It's looking for "\d", not digits.

So...

var regOrderNo = new RegExp("\\d{6}");
Illandril
Actually, it's looking for `/d{6}/`, not `\d` : )
kangax
+3  A: 

You have to escape your \ when used inside a string.

new RegExp("\\d{6}");

or

/\d{6}/
Chetan Sastry