search
Homephp教程php手册PHP正则匹配中文字母数字正则表达式

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

Jun 13, 2016 am 11:33 AM
echomatchphponeChinesecodematchletternumbermethodregularexpression

 方法一

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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.