priyamp mp1 priyamp mp1 - 7 months ago 23
PHP Question

Yii preg match Not allowed Numbers only

How to avoid numbers only in Name Validation in php? I want to do Name Allowed space,dot,special character,string but not allowed Numbers only How?

Am using below code,

array('first_name,last_name', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u', 'message' => '{attribute} contain Alphabets only',),


It not allowed Special character too?

Answer
<?php
$string='a123';
if(preg_match('/[0-9]/',$string)){
    echo 'you are not allowed to use numbers';
}else{
    //proceed
}

?>