What is the regex to allow dashes and numbers only?
A good example is use in a phone number. e.g. 555-555-555, 12-2314-425.
I don’t want entries like: ------------- though but -34--53-343 is fine for now.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
So in the problem as stated, you want at least one digit but otherwise any of 0-9 or dash.
If you’re trying to recognize phone numbers, you probably want something that recognizes sequences of digits optionally separated by single dashes, try this instead:
Which excludes leading or trailing dashes and doubled dashes.