How to determine whether a character is a Chinese character in ASP?
Source: Internet
Author: User
In program design, we often need to check whether the user input is correct, especially the name, address, and so on, is not the input Chinese character. How can we determine whether a character is a Chinese character? There are at least two methods in asp.
1. convert a character into an ascii code using asc. If it is an English character, it should be in the range of 0-127, while the Chinese character is a relatively large number, so you can use the following code to determine:
If abs (asc (whichchar)> 127 then
Response. write whichchar & "is a Chinese character"
Else
Response. write whichchar & "not a Chinese character"
End if
2. the unicode encoding range of Chinese characters is 4e00-9fa5, so you can use regular expression to determine whether a Chinese character is a Chinese character.
Set regexpobj = new regexp
Regexpobj. pattern = "^ [\ u4e00-\ u9fa5] + $"
Regcheck = regexpobj. test (whichchar)
Set regexpobj = nothing
If regcheck then
Response. write whichchar & "is a Chinese character"
Else
Resposne. write whichchar & "not Chinese character"
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