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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:07:45+00:00 2026-06-15T17:07:45+00:00

I wrote Regex to allow only digits. It is @[0-9] and it works perfectly.

  • 0

I wrote Regex to allow only digits. It is @"[0-9]" and it works perfectly. But I would like to add a symbol “-” in regex. I want to allow digits and “-“. How to do it?)
I’ve tried such mask @"[0-9]\{-}" but it allows nothing.


I have seen recently that if I input hyphen then my program does not understand as “hyphen”. This is a reason why your all masks did not work. Nevertheless, they are all correct. Thanks a lot for your help. Now I will find how to read hyphen as “-” in WPF 2010.

  • 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-15T17:07:46+00:00Added an answer on June 15, 2026 at 5:07 pm

    Hypens (-) do not act like range specifiers at the beginning of a character set, so you can do this with the regex

    @"[-0-9]"
    

    or if, like in most regex engines, WPF allows character set shorthands in character sets, you can also use

    @"[-\d]"
    

    or, as the other answers mentioned, you can escape the - to put it in the regex, as in either of these two regular expressions

    @"[0-9\-]"
    @"[\d\-]"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a regex to fetch string from HTML, but it seems the multiline
I wrote the following regex in perl and now i want to write it
So I'm not sure if I understand how this works and would like a
I need to build a regex that allows only letters and hyphens, but it
I wrote this regex: \\s+(?:([^:]+):)(?:([^:]+):)(?:([^:]+):)(?:([^:]+):) to parse such things: lvt:vgt:mwi-ao:44.00m::::lvt_mlog:100.00: lvt2:vgt2:-wi-a-:908.00m:::::: And 1 group
I build a mechnism using JS for accepting only digits : However I want
I need to tell my FOSUSer admin that I want to allow only admin
TST0001-ABI-NGW-000003 the above is my string want to write a regex which allow just
I am trying to write a regex to get the numbers from strings like
I need to write some Javascript to check an input to only allow number

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.