Reputation: 153
I have found a lot of different patterns on the net (tested them all), i have also added encoding to the page, but nothing seams to work. This is my code:
<?php header('Content-Type: text/html; charset=utf-8'); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$teststring="cc12cž";
$pattern = "/^[p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u";
if(preg_match($pattern, $teststring))
{echo"IT IS ALFANUMERIC";}
else
{echo"ERROR";}
?>
</body></html>
This is what i tried
//$pattern = "/^[\p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u";
//$pattern = "/^[p{L}\p{M}\a-zA-Z*0-9\s\-]+$/u"
//$pattern ='/^[a-zA-Z\p{Cyrillic}\d\s\-]+$/u'
//$pattern ="/(*UTF8)^[[:alnum:]]+$/"
//$pattern ="/^[a-zA-Z\p{Cyrillic}\p{Cyrillic}]+$/u"
Upvotes: 3
Views: 1097
Reputation: 27866
I did a test using ZF Zend_Validate_Alnum and your string seems to validate correctly.
$validator = new Zend_Validate_Alnum();
if ($validator->isValid('cc12cž')) {
// value contains only allowed chars
echo "IT IS ALFANUMERIC";
} else {
echo "ERROR";
}
From what I see their validation technique is quite simple and it does not involve regexp
:
if (!is_string($value) && !is_int($value) && !is_float($value)) {
$this->_error(self::INVALID);
return false;
}
Upvotes: 3