Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i use preg_match with alphanumeric and unicode acceptance?

I am going to build a multilingual website with PHP and need to have a preg_match which passes all Unicode characters and numbers.
i.e I need it to pass English letters, Spanish letters,Italian letters and as you may know I don't want to pass other characters like ' " _ - and ...

I want some thing like this :

$pattern='/^[unicode chars without \'-_;?]*$/u'; 
if(!preg_match($pattern, $url))
   echo #error;
like image 249
M Rostami Avatar asked May 28 '12 15:05

M Rostami


1 Answers

Unicode property for letter is \pL so in preg_match:

preg_match('/^\pL+$/u', $string);

for an url you could add numbers \pN and dot:

preg_match('/^[\pL\pN.]+/u', $string);
like image 148
Toto Avatar answered Oct 28 '22 14:10

Toto