We often encounter verification characters or Chinese Characters in ASP. NET. We searched for some good examples and solutions on the Internet and listed them for sharing with you.
You can use a regular expression to verify Chinese characters, numbers, and characters.
A method found on the internet is provided:
Source: http://www.cnblogs.com/flashicp/archive/2007/06/13/782355.html
1. A regular expression that only contains Chinese characters, numbers, letters, and underscores. It cannot start or end with or after the following line:
^ (?! _)(?!. *? _ $) [A-zA-Z0-9 _/u4e00-/u9fa5] + $ where:
^ Match the start point of the string
(?! _) Cannot start _
(?!. *? _ $) Cannot end _
[A-zA-Z0-9 _/u4e00-/u9fa5] + at least one Chinese character, number, letter, underline
$ Match the end of the string
Add @ in front of the program; otherwise, escape @ "^ (?! _)(?!. *? _ $) [A-zA-Z0-9 _/u4e00-/u9fa5] + $"
(Or: @ "^ (?! _)/W *(? <! _) $ "Or @" ^ [/u4e00-/u9FA50-9a-zA-Z _] + $ ")
2. It only contains Chinese characters, numbers, letters, and underscores. The underline is not limited to any position:
^ [A-zA-Z0-9 _/u4e00-/u9fa5] + $
3. A string consisting of digits, 26 English letters, or underscores
^/W + $
4, 2 ~ 4 Chinese Characters
@ "^ [/U4e00-/u9fa5] {2, 4} $ ";
5,
^ [/W-] + (/. [/W-] +) * @ [/W-] + (/. [/W-] +) + $
Analysis with :( ABC) +: xyzabcabcabcxyzabcab
XYZAbcAbcAbcXYZAbcAb
6,
[^/U4e00-/u9FA50-9a-zA-Z _]
34555 # 5' --> 34555#5'
[/U4e00-/u9FA50-9a-zA-Z _] eiieng_89 _ ---> eiieng_89 _
_ '; 'Eieng _ 88 & * 9 _ --> _'; 'eieng _ 88 & * 9 _
_ '; 'Eieng _ 88 _ & * 9 _ --> _'; 'eieng _ 88 _ & * 9 _
Public bool regexname (string Str)
{
Bool flag = RegEx. ismatch (STR, @ "^ [a-zA-Z0-9 _/u4e00-/u9fa5] + $ ");
Return flag;
}
RegEx Reg = new RegEx ("^ [a-zA-Z_0-9] + $ ");
If (Reg. ismatch (s ))
{
// Meets the rules
}
Else
{
// Invalid characters exist
}