. NET Common Regular Expression Functions

Source: Internet
Author: User
Tags dot net

The Application of dot net regular expressions is also indispensable in dot net development.

Public class regularfun
{

Public regularfun ()
{
}

/// <Summary>
/// Determine whether a number is an integer
/// </Summary>
/// <Param name = "strnumber"> string </param>
/// <Returns> </returns>
Public static bool isinteger (string strnumber)
{
RegEx objnotintpattern = new RegEx ("[^ 0-]");
RegEx objintpattern = new RegEx ("^-[0-9] + $ | ^ [0-9] + $ ");
Return! Objnotintpattern. ismatch (strnumber )&&
Objintpattern. ismatch (strnumber );
}

/// <Summary>
/// Determine whether only characters and numbers are composed.
/// </Summary>
/// <Param name = "strtocheck"> </param>
/// <Returns> </returns>
Public static bool isalphanumeric (string strtocheck)
{
RegEx objalphanumericpattern = new RegEx ("[^ a-zA-Z0-9]");
Return! Objalphanumericpattern. ismatch (strtocheck );
}
/// <Summary>
/// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".
/// </Summary>
/// <Param name = "username"> </param>
/// <Returns> </returns>
Public static bool isregusername (string username)
{
RegEx objalphanumericpattern = new RegEx ("^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ ");
Return! Objalphanumericpattern. ismatch (username );
}

/// <Summary>
/// Password verification: only 6-20 letters, numbers, and underscores can be entered
/// </Summary>
/// <Param name = "password"> </param>
/// <Returns> </returns>
Public static bool ispassword (string password)
{
RegEx objalphanumericpattern = new RegEx (@ "^ (\ W) {6, 20} $ ");
Return! Objalphanumericpattern. ismatch (password );
}

/// <Summary>
/// Check the common phone number and fax number. It can start with "+" and contain "-" in addition to numbers.
/// </Summary>
/// <Param name = "tel"> </param>
/// <Returns> </returns>
Public static bool istelepone (string Tel)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ ");
Return! Objalphanumericpattern. ismatch (TEL );
}

/// <Summary>
/// Verify the mobile phone number: it must start with a number and can contain "-" in addition to a number.
/// </Summary>
/// <Param name = "mobile"> </param>
/// <Returns> </returns>
Public static bool ismobil (string mobile)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ ");
Return! Objalphanumericpattern. ismatch (mobile );
}

/// <Summary>
/// Check the IP address
/// </Summary>
/// <Param name = "ipaddr"> </param>
/// <Returns> </returns>
Public static bool isipaddress (string ipaddr)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [0-9.] {1, 20} $ ");
Return! Objalphanumericpattern. ismatch (ipaddr );
}

}

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.