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 6854871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:41:15+00:00 2026-05-27T01:41:15+00:00

I have a written a Regex to check whether the string consists of 9

  • 0

I have a written a Regex to check whether the string consists of 9 digits or not as follows but this always returning me false even if I have my string as 123456789.

if (Regex.IsMatch(strSSN, " ^\\d{9}$"))

Can any one tell what’s wrong and also if any better one provide me .. What i am achieving is the string should have only numeric data and the length should be =9

  • 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-05-27T01:41:16+00:00Added an answer on May 27, 2026 at 1:41 am

    Spaces are significant in regular expressions (and of course, you can’t match a space character before the start of the string). Remove it and everything should be fine:

    if (Regex.IsMatch(strSSN, "^\\d{9}$"))
    

    Also, you generally want to use verbatim strings for regexes in C#, so you don’t have to double your backslashes, but this is just a convenience, not the reason for your problem:

    if (Regex.IsMatch(strSSN, @"^\d{9}$"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have written regex to check where ther string have the char like
I have written this regex that works, but honestly, it’s like 75% guesswork. The
I have written following regex But its not working. Can you please help me?
I have written a Regex which will take only integers but I need to
I have written a regex to match section of an SQL Connection string. In
Hoping you can help. Pretty new to regex and although I have written this
I have written the following regex to match a set of e-mails from HTML
I have written a class using std::tr1::regex, and I don't know how to link
I have written this regexp: <(a*)\b[^>]*>.*?</\1> and is tested on this regexp testing site:
have written this little class, which generates a UUID every time an object of

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.