0

I need a regular expression that allows english alphabets and numbers and "-" and not allow every thing else. but recently I found out that my regular expression not stopping french language alphabets and numbers

My regular expression is as follow,

@"[^\w\d-]"; 

How can I change the above regular expression so only english alphabets, numbers and "-" can be allowed only?

4
  • FYI that would also allow _ Commented Dec 22, 2014 at 12:59
  • Try this A-Za-z And I think you need the - as a - to be first Commented Dec 22, 2014 at 12:59
  • Move the caret outside square brackets. Commented Dec 22, 2014 at 13:00
  • See duplicate, replace underscore (_) with dash (-). Commented Dec 22, 2014 at 13:02

1 Answer 1

3

How can I change the above regular expression so only english alphabets, numbers and "-" can be allowed only?

@"^[A-Za-z0-9-]+$" 

^ asserts that we are at the start. $ Asserts that we are at the end. + repeats the previous token one or more times.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.