Jump to content

Problems matching with preg_match on Swedish characters ÅÄÖ

Go to solution Solved by ChrisFredriksson,

Recommended Posts

Hey everyone,

I've been having troubles previously, some months to some year ago, with preg_match'ing on Swedish characters ÅÄÖ. I had no luck whatsoever after a few hours of trying different variations and today I wanted to revisit this as it is still a problem.

But I just can't figure out why it doesn't work, so I'm hoping you guys can help me out!


I have this preg_match;

preg_match('/^[a-z A-Z\Å\å\Ä\ä\Ö\ö\s*\d]+$/u', $variable)

and as soon as I have any ÅÄÖ in the variable, it just doesn't want to match on it.

Could you please help me out before I throw the computer out the window? 😥😥😥

What I want is to only allow a-z A-Z and the Swedish characters ÅÄÖåäö - it is a match for first/lastname of a person.

Link to comment
Share on other sites

Hi requinix, Thanks for the quick reply!

I do believe it must be using UTF-8.. But I think I've finally figured it out, before I saw your reply.. The $variable gets the data from a GET var and I preprocess this to make sure nothing illegal is there, it seems that I'm a bit too aggresive and filtering even valid characters 😂

When I tried just a regular $_GET it worked perfectly.. so at least I know where the problem is now.

Thanks however! I really appreciate the quick reply and I'm try and figure this out. If, or hopefully when, I find out the culprit I'll post here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.