當前位置:學者齋 >

計算機 >php語言 >

PHP正則匹配中文字母數字正則的表達式

PHP正則匹配中文字母數字正則的表達式

PHP語言是一門實用性很強的語言,下面小編為大家帶來了關於PHP正則匹配中文字母數字正則的'表達式,歡迎大家閲讀!

PHP正則匹配中文字母數字正則的表達式
  PHP正則匹配中文字母數字正則的表達式

代碼如下

if(preg_match("/^d*$/", "4312"))

{

echo "全數字

";

}

if(preg_match("/^[a-z]*$/i", "fdsFDfd"))

{

echo "全字母

";

}

if(preg_match("/^[a-zd]*$/i", "fd4fd34"))

{

echo "有數字有字母

";

}

中文漢字

代碼如下

$username=$_REQUEST['username'];

if(!preg_match("/^[a-z0-9xa1-xff]{3,10}$/",$username))

{

echo"34r345";

exit;

}

上面是比較散的,下面把幾個總結到一起來

代碼如下

$input_tag = $_POST['tag'];

$input_tag = explode(',', $input_tag);

$input_tag = array_unique($input_tag);

$input_tag = array_diff($input_tag, array(null));

$leng = '';

$true = '';

$comma = '';

foreach ($input_tag as $v) {

if (strlen($v) > 18) {

$leng .= $comma . $v;

$comma = ',';

}

$true .= $comma . $v;

$comma = ',';

}

$true = str_replace(',', '', $true);

if (!preg_match('/^[x80-xff_a-zA-Z0-9]+$/', $true)) {

echo "";

exit;

}

if (!empty($leng)) {

echo "";

exit;

}

  • 文章版權屬於文章作者所有,轉載請註明 https://xuezhezhai.com/zh-hk/jsj/php/o654je.html