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

PHP,一個嵌套的縮寫名稱,是英文超級文本預處理語言(PHP:Hypertext Preprocessor)的縮寫。PHP 是一種 HTML 內嵌式的.語言,PHP與微軟的ASP頗有幾分相似,都是一種在服務器端執行的嵌入HTML文檔的腳本語言,語言的風格有類似於C語言,現在被很多的網站編程人員廣泛的運用。下面是小編爲大家帶來的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 "<script>alert('不允許特殊符號的!!!');</script>";

exit;

}

if (!empty($leng)) {

echo "<script>alert('一個標籤只能是6個漢字以內哦!!!');</script>";

exit;

}