search
Homephp教程php手册中文验证函数(php javascript)

中文验证函数(php javascript)

Jun 13, 2016 am 09:54 AM
javascriptphpChinesefunctionjudgmentcharacterstringyesofcodingverify

中文字符判断是根据字符串编码来的,/^[chr(0xa1)-chr(0xff)]+$这就是判断是否为中文的php验证正则表达式 下面来看一个验证中文实例

中文字符判断是根据字符串编码来的,/^[chr(0xa1)-chr(0xff)]+$这就是判断是否为中文的php教程验证正则表达式
下面来看一个验证中文实例


$str = "一聚教程网";
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "这是一个纯中文字符串";
} else {
echo "这不是一个纯中文字串";
}

js

var str = "php编程";
if (/^[u4e00-u9fa5]+$/.test(str)) {
alert("该字符串全部是中文");
} else {
alert("该字符串不全部是中文");
}

php

if($en_utf8)
{    $joid = preg_replace("[^0-9a-za-z_-|x4e00-x9fa5|:|/|#|.]","",$joid);             }   //utf-8的中文匹配
else
{    $joid = preg_replace("[^0-9a-za-z_-|".chr(0xa1)."-".chr(0xff)."|:|/|#|.]","",$joid);   }   //gb2312的中文匹配


php中来判断字符串是否为中文,就会沿袭这个思路:

$str = "php编程";
if (preg_match("/^[u4e00-u9fa5]+$/",$str)) {
print("该字符串全部是中文");
} else {
print("该字符串不全部是中文");
}
?>

 

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot 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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment