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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:29:24+00:00 2026-05-24T10:29:24+00:00

I am new to Asp.Net and I want to validate SSN using regularexpressionvalidator. In

  • 0

I am new to Asp.Net and I want to validate SSN using regularexpressionvalidator. In the regularexpressionvalidator I gave regularexpression as :

ValidationExpression="\d{3}-\d{2}-\d{4}"

My regular expression works fine. It says 3 digits then – then 2 digits then – then 4 digits.

However I also want the regular expression to succeed when the textbox is full empty or the textbox contains just:

_ _ – _-_ _ _ _

where _ stands for “space” (not _. I’ve shown _ just so editor can show it up on SO).

How can I do that with regularexpressionvalidator?

  • 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-24T10:29:26+00:00Added an answer on May 24, 2026 at 10:29 am

    This pattern should meet all three use cases:

    ^([ ]{3}-[ ]{2}-[ ]{4}|\d{3}-\d{2}-\d{4})$
    

    I used literal spaces in a character array above rather than \s, because \s would have also matched tabs, newlines, and other whitespace characters. Also, it is important to keep the space and digit tests separate, not in the same subpattern, otherwise you’d match junk input like 123-__-6_8_.

    Edited: @Dan correctly noted in his answer that the ^ and $ should surround the entire pattern so we match the entire string, not just find an SSN somewhere within it.

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

Sidebar

Related Questions

I am new In ASP.NET, I want to create to Login Form using Membership
I am building a new asp.net MVC3 web application for reporting and I want
I am new to ASP.NET MVC 3 and I want to have username/id as
i am new to asp.net, ı want to get data from url on asp.net.
I'm new with ASP.NET, and I want to use a simple technique that I
When user clicks hyperlink on my ASP.NET page, I want a new browser to
In a brand new ASP.NET MVC2 project, I want the user to be redirected
After creating a new ASP.NET Web Service I want it only to support HTTP-POST
I'm pretty new in ASP.net, and im trying to validate some output from my
I´m using C# and ASP.NET for developing in Windows Azure. I want to do

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.