Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Regular Expression to match six-digit number [duplicate]

I am trying to incorporate a regular expression i have used in the past in a different manner into some validation 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?

like image 528
Billy Logan Avatar asked Jun 05 '26 22:06

Billy Logan


1 Answers

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

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

or

/\d{6}/
like image 73
Chetan S Avatar answered Jun 08 '26 15:06

Chetan S