"C #" regular Expressions match Chinese, English letters and numbers and _ Writing! and control the length of __ regular expressions

Source: Internet
Author: User
using System.Text.RegularExpressions;

Match Chinese: [\u4e00-\u9fa5]

English letter: [A-za-z]

Number: [0-9]

Match Chinese, English letters and numbers and _:
^[\u4e00-\u9fa5_a-za-z0-9]+$

At the same time determine the input length:
[\u4e00-\u9fa5_a-za-z0-9_] {4,10}

^[\w\u4e00-\u9fa5\uf900-\ufa2d]*$1, a regular expression containing only Chinese characters, numbers, letters, underscores cannot begin and end with an underscore:
^(?! _)(?!. *?_$) [a-za-z0-9_\u4e00-\u9fa5]+$ of which:
^ matches where the string begins
(?! _) cannot start with _
(?!. *?_$) cannot end with _
[a-za-z0-9_\u4e00-\u9fa5]+ at least one Chinese character, number, letter, underline
$ matches where the string ends

Put @ in front of the program, or you need to escape @ ^ (?! _)(?!. *?_$) [a-za-z0-9_\u4e00-\u9fa5]+$]
(or: @ "^" ^ (?!) _) \w* (?
2, only contain Chinese characters, numbers, letters, underline, the underline position is not limited:
^[a-za-z0-9_\u4e00-\u9fa5]+$

3. A string of numbers, 26 English letters, or underscores
^\w+$

4.2~4 a Chinese character
@ "^[\u4e00-\u9fa5]{2,4}$";

5,
^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$

Used: (ABC) + to analyze: XYZAbcAbcAbcXYZAbcAb

Xyz ABCABCABCXyz ABCAb6,
[^\u4e00-\u9fa50-9a-za-z_]
34555#5 '-->34555 #5 '

[\u4e00-\u9fa50-9a-za-z_] eiieng_89_--->eiieng_89_
_';' eiieng_88&*9_-->_ '; ' Eiieng_88&*9_
_';' eiieng_88_&*9_-->_ '; ' Eiieng_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))
{
\ Compliance Rules
}
Else
{
\ \ There are illegal characters
}

no longer than 7 characters, or 14 bytes (digits, letters and underscores) regular Expressions
^[\u4e00-\u9fa5]{1,7}$|^[\da-za-z_]{14}$
Related Article

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.