Use regular expressions in C # To verify the phone number, mobile phone number, ID card number, number, and zip code

Source: Internet
Author: User

Http://www.cnblogs.com/wuhuisheng/archive/2011/03/23/1992652.html

The main code for phone number verification is as follows:

Public bool istelephone (string str_telephone)

{

Return System. Text. regularexpressions. RegEx. ismatch (str_telephone, @ "^ (\ D {3, 4 }-)? \ D {6, 8} $ ");

}

The main code used to verify the mobile phone number is as follows:

Public bool ishandset (string str_handset)

{

Return System. Text. regularexpressions. RegEx. ismatch (str_handset, @ "^ [1] + [3, 5] + \ D {9 }");

}

The main code for verifying the ID card number is as follows:

Public bool isidcard (string str_idcard)

{

Return System. Text. regularexpressions. RegEx. ismatch (str_idcard, @ "(^ \ D {18} $) | (^ \ D {15} $ )");

}

The main code for verifying that the input is a number is as follows:

Public bool isnumber (string str_number)

{

Return System. Text. regularexpressions. RegEx. ismatch (str_number, @ "^ [0-9] * $ ");

}

The main code to verify the zip code is as follows:

Public bool ispostalcode (string str_postalcode)

{

Return System. Text. regularexpressions. RegEx. ismatch (str_postalcode, @ "^ \ D {6} $ ");

}

/// <Summary>
/// Verify the email address
/// </Summary>
/// <Param name = "str_email"> </param>
/// <Returns> </returns>
Public bool isemail (string str_email)
{
Return System. text. regularexpressions. regEx. ismatch (str_email, @ "\ W {1, }@\\ W {1 ,}\\. \ W {1 ,}");
}

-- From the C # programming dictionary

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.