Home  >  Article  >  Backend Development  >  PHP regular matching Chinese alphanumeric regular expression_PHP tutorial

PHP regular matching Chinese alphanumeric regular expression_PHP tutorial

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

Method 1

The code is as follows
if(preg_match("/^d*$/", "4312"))
{
echo "All numbers
";
}

if(preg_match("/^[a-z]*$/i", "fdsFDfd"))
{
echo "Full letters
";
}

if(preg_match("/^[a-zd]*$/i", "fd4fd34"))
{
echo "There are numbers and letters
";
}

Chinese characters

The code is as follows
$username=$_REQUEST['username'];
if(!preg_match("/^[a-z0-9xa1-xff]{3,10}$/",$username))
{
echo "34r345";
exit;
}


The above is relatively scattered, let’s summarize a few together

The code is as follows
$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('Special symbols not allowed!!!');</script>";
exit;
}

if (!empty($leng)) {
echo "<script>alert('A label can only be within 6 Chinese characters!!!');</script>";
exit;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371982.htmlTechArticleThe code for method one is as follows if(preg_match(/^d*$/, 4312)) { echo all numbers; } if(preg_match(/^[a-z]*$/i, fdsFDfd)) { echo all letters; } if(preg_match(/^[a-zd]*$/i, fd4fd34)) { echo There are several...
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