Johan
Johan

Reputation: 35213

Words with letter and numbers that can contain dashes and swedish characters

I would like to create a regexp which validates against all english letters + the swedish "åäö (lower and uppercase)". Also, the word can contain 1 or more "-" and can be of any length.

^[a-zA-Z\dåäöÅÄÖ\-*]*$

Is this correct? Can it be improved? If I recall correctly, a-zA-Z icludes more than just those letters (some characters in the ascii table between a-z and A-Z).

http://regexr.com?36svf

Update: Here are the characters that I'm refering to:

Update 2: I also want to include digits.

enter image description here

Upvotes: 1

Views: 874

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336418

Your regex is OK, but why are you including the asterisk (*)?

[A-Za-z] only matches ASCII letters, it's [A-z] that's problematic because there are some special characters between Z and a.

So ^[a-zA-Z\dåäöÅÄÖ-]*$ should be OK.

Upvotes: 1

Related Questions