Reputation: 718
In an application which is intended for germany ,am writing some webservices i have to apply some validation rules for username ,password etc.. like alphanumeric,special charecters not supported etc.. i have used regular expression to achive this but it fails,it works fine for english language,but it does not support German language, how can i tackle this issue.
Any help will be appreciated...preg_match("#.*^(?=.{8,20})(?=.*[a-zA-Z])(?=.*[0-9]).*$#", $string)
Upvotes: 4
Views: 905
Reputation: 14345
First, use the 'u' modifier for UTF-8 (whose encoding you should be using for international applications). Secondly, if you are trying to allow umlauts, etc. within the [a-zA-Z] block, you can add the specific characters you want using escape sequences as follows:
individually:
preg_match( "/\x{00FC}/u" , 'ü' ); // 1
or in a group:
preg_match('/^[\x{00DF}\x{00E4}\x{00C4}\x{00F6}\x{00D6}\x{00FC}\x{00DC}]+$/u', 'ßäÄöÖüÜ'); // 1
...or just use the word letter match \w
(noting that this will also allow numbers and underscore and other international characters which can serve as word letters).
preg_match( "/\w/u" , 'ü' ); // 1
(I'm not sure what you are doing with the ^
in the middle of the expression, btw, without an 'm' modifier.)
Upvotes: 1