Heim  >  Artikel  >  Backend-Entwicklung  >  PHP正则匹配中文字母数字正则表达式_PHP教程

PHP正则匹配中文字母数字正则表达式_PHP教程

WBOY
WBOYOriginal
2016-07-20 11:17:332156Durchsuche

 方法一

 代码如下
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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/371982.htmlTechArticle方法一 代码如下 if(preg_match(/^d*$/, 4312)) { echo 全数字 ; } if(preg_match(/^[a-z]*$/i, fdsFDfd)) { echo 全字母 ; } if(preg_match(/^[a-zd]*$/i, fd4fd34)) { echo 有数...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn