Chinese verification function (phpjavascript) _ PHP Tutorial

Source: Internet
Author: User
Chinese verification function (phpjavascript ). The Chinese character is determined by String Encoding. ^ [chr (0xa1)-chr (0xff)] + $ this is the regular expression for php verification to determine whether it is a Chinese character. Next, let's look at the regular expression for verifying the Chinese character. the Chinese character determination is based on string encoding./^ [chr (0xa1) -chr (0xff)] + $ this is the regular expression for php verification to determine whether it is a Chinese character. let's look at an example of Chinese verification.

The determination of Chinese characters is based on string encoding,/^ [chr (0xa1)-chr (0xff)] + $ this is the php Tutorial to verify whether the regular expression is Chinese
The following is an example of verifying Chinese characters.


$ Str = "yijucheng ";
If (preg_match ("/^ [". chr (0xa1). "-". chr (0xff). "] + $/", $ str )){
Echo "this is a pure Chinese string ";
} Else {
Echo "this is not a pure Chinese string ";
}

Js

Var str = "php programming ";
If (/^ [u4e00-u9fa5] + $/. test (str )){
Alert ("all strings are Chinese ");
} Else {
Alert ("Not all strings are Chinese ");
}

Php

If ($ en_utf8)
{$ Joid = preg_replace ("[^ 0-9a-za-z _-| x4e00-x9fa5 |: |/| # |.]", "", $ joid);} // UTF-8 Chinese match
Else
{$ Joid = preg_replace ("[^ 0-9a-za-z _-| ". chr (0xa1 ). "-". chr (0xff ). "|: |/| # |.] "," ", $ joid);} // gb2312 Chinese match


To determine whether a string is Chinese in php, we will follow this idea:

$ Str = "php programming ";
If (preg_match ("/^ [u4e00-u9fa5] + $/", $ str )){
Print ("all strings are Chinese ");
} Else {
Print ("Not all strings are Chinese ");
}
?>

Explain (0xa1)-chr (0xff)] + $ this is the php validation regular expression that determines whether it is Chinese. Next let's look at a validation Chinese instance Chinese character sentence...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.