I have never got my head around using regular expressions, so I have a bit of an issue understanding why my below listed regex. doesn’t only allow the below listed characters:
- A-Z & a-z (upper & lower)
- ÅÄÖ & åäö
- 0-9 & _ (underscore)
Here’s the regex:
/^[\s\da-0-9-zA-ZåäöÅÄÖ_]$/i
What am I doing wrong?
Because this
a-0-9-zis in reverse order. Use this:^[\s\da-zA-ZåäöÅÄÖ_]$or this:(?i)^[\s\da-zåäö_]$with ignore case option set to enabled.Also you can use special character
\w, which means:letters, digits, and underscoresIn you regex you’re using
\dand0-9.\dincludes0-9, see Explanation