Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8403085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:15:04+00:00 2026-06-09T22:15:04+00:00

I am trying to validate a variable contains a 9-digit number in Javascript. This

  • 0

I am trying to validate a variable contains a 9-digit number in Javascript. This should be basic but for some reason this is failing:

    var test = "123123123";
    var pattern = new RegExp("/\d{9}/");

    if(test.match(pattern))
    {
        //This code never executes
    }
    else
    {
        //This code is always executing
        alert('no match!'); 
    }

Can anyone see why I am not getting a match?

I also tried type-casting test to an integer with:

test = Number(test);

…but this doesn’t work as it has to be a String to support the .match method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:15:05+00:00Added an answer on June 9, 2026 at 10:15 pm

    You’re mixing the two different regex constructors. Pick one:

     var pattern = new RegExp("^\\d{9}$");
     // or
     var pattern = /^\d{9}$/;
    

    N.B. you probably want to add start and end anchors (as above) to make sure the whole string matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i am trying to call this function in my javascript but it gives
I'm having this problem with validating a document that contains some basic PHP variables.
I am trying to validate National Identity Card Number in my application. But It
I am trying to validate an e-mail address using javascript. The problem is the
I'm trying to validate an ID. I have this class called ManejadorTickets in which
I am currently trying to validate some front-end values with some server-side methods (as
I'm trying to write a regular expression that will validate a variable assignments in
I am trying to validate input login via javascript by passing PHP variables. I
I'm trying to validate some POST data. One of the validations I need to
I was trying to validate my User model data and I came upon this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.