Some simple verification (Chinese and digital verification)

Source: Internet
Author: User

^ [\ U4e00-\ u9fa5] {} $ this is a regular expression used to verify Chinese Characters

System. Text. encoding. Default. getbytecount (strstring); -- returns the number of bytes.

// Determine whether the string is a number.
String str1 = This. textbox1.text. Trim ();
If (RegEx. ismatch (str1, @ "^ \ D + $ "))
{
MessageBox. Show ("yes."); // yes;
}
Else
MessageBox. Show ("not a number ");
Return;
//

// Using system. Text. regularexpressions;
String STR = "23sd SDF 95 columns gfwef 56 countries anywhere Ge ga 4 ";
Matchcollection MS = RegEx. Matches (STR, "[\ u4e00-\ u9fa5]");
String SSS = NULL;
For (INT I = 0; I <Ms. Count; I ++)
{
SSS + = MS [I]. value;
}
MessageBox. Show (SSS );

If (RegEx. ismatch (STR, "[0-9]") // number
MessageBox. Show ("the string contains numbers ");
If (RegEx. ismatch (STR, "[A-Z]") // lowercase letter
MessageBox. Show ("the string contains lowercase letters ");
If (RegEx. ismatch (STR, "[A-Z]") // uppercase letter
MessageBox. Show ("the string contains lowercase letters ");
If (RegEx. ismatch (STR, "[A-Za-Z]") // all letters
MessageBox. Show ("the string contains letters ");
If (RegEx. ismatch (STR, "[\ u4e00-\ u9fa5]") // Chinese Character
MessageBox. Show ("the string contains Chinese characters ");

}

 

If (islength (textbox. Text, 100) = false) // exceeds 100 words

Public bool islength (string STR, int maxlength)
{
Char C;
Int intlength = 0;

For (INT I = 0; I <Str. length; I ++)
{
C = STR [I];
 
If (C <128) | (C> 160) & (c <224) | (C> 65376) & (c <65439 )))
{
Intlength ++;
}
Else
{
Intlength + = 2;
}
}

If (intlength> maxlength)
{
Return false;
}

Return true;
}

 

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.