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 az and AZ).
Update: Here are the characters that I'm refering to:
Update 2: I also want to include digits.
Your regex is OK, but why are you including the asterisk ( *
)?
[A-Za-z]
only matches ASCII letters, it's [Az]
that's problematic because there are some special characters between Z
and a
.
So ^[a-zA-Z\\dåäöÅÄÖ-]*$
should be OK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.