Jump to content
php.lv forumi

advanced preg_match


cucumber

Recommended Posts

preg_match, vai ir iespejams uzrakstit, tadu masku, kas skatas vai varda ir kaut >=1 lielais burts, >=1 mazais burts, 1>= cipars

tas ir

qwertY123 -> ok

Qwery123 -> ok

1Q3asdffa -> ok

qwerty123 - wrong

Qwertyaf - wrong

utt. ?

Link to comment
Share on other sites

piečuks no tevis :p

$ex  = '/([a-z]{1,}[A-Z]{1,}[0-9]{1,})|';
$ex .= '([a-z]{1,}[0-9]{1,}[A-Z]{1,})|';
$ex .= '([0-9]{1,}[A-Z]{1,}[a-z]{1,})|';
$ex .= '([0-9]{1,}[a-z]{1,}[A-Z]{1,})|';
$ex .= '([A-Z]{1,}[0-9]{1,}[a-z]{1,})|';
$ex .= '([A-Z]{1,}[a-z]{1,}[0-9]{1,})/';
foreach(array('qwertY123','Qwery123','1Q3asdffa','qwerty123','Qwertyaf') as $str)
{
 echo '<br />'.$str;
 if(preg_match($ex, $str)){echo ' OK';} else { echo ' WRONG';};
}

Edited by v3rb0
Link to comment
Share on other sites

samera sarezgiti sanak, vieglak laikam ir:

 

if (preg_match("/[a-z]/",$someword) ) $a=1

if (preg_match("/[A-Z]/",$someword) )$b=1

if (preg_match("/[0-9]/",$someword) )$c=1

 

if ($a==1 && $b==1 && $c==1) echo ("OK");

Link to comment
Share on other sites

×
×
  • Create New...