Favorite regular expressions in asp.net development

Source: Internet
Author: User

It provides several regular expressions that are commonly used in development. For example, if you have phone number, mobile phone number, email address, or url, you may want to check the regular expression.
First: verify whether the input string is a number.

View code // <summary>

/// Verify that the input string is a number
/// </Summary>
/// <Param name = "p_str_num"> input character </param>
/// <Returns> returns a boolean value. </returns>
Public bool validatenum (string p_str_num)
        {
Return regex. ismatch (p_str_num, "^ [0-9] * $ ");
        }

 

Second: verify whether the input string is a phone number.

Verify that the input string is a phone number. // <summary>
/// Verify whether the input string is a telephone number
  

/// </Summary>
/// <Param name = "p_str_phone"> input string </param>
/// <Returns> returns a boolean value. </returns>
Public bool validatephone (string p_str_phone)
        {
Return regex. ismatch (p_str_phone, @ "d {3, 4}-d {7, 8 }");
        }


Third: verify that the input string is a fax number

Verify that the input string is a fax number. // <summary>
/// Verify whether the input string is a fax number
 

/// </Summary>
/// <Param name = "p_str_fax"> input string </param>
/// <Returns> returns a boolean value. </returns>
Public bool validatefax (string p_str_fax)
        {
Return regex. ismatch (p_str_fax, @ "86-d {2, 3}-d {7, 8 }");
        }


Fourth: verify whether the input string is a zip code

Verify that the input string is a zip code. // <summary>
/// Verify whether the input string is a zip code

/// </Summary>
/// <Param name = "p_str_postcode"> input string </param>
/// <Returns> returns a boolean value. </returns>
Public bool validatepostcode (string p_str_postcode)
        {
Return regex. ismatch (p_str_postcode, @ "d {6 }");
        }

Fifth: verify whether the input string is an e-mail address

Verify whether the input string is an e-mail address. // <summary>
/// Verify whether the input string is an email address

/// </Summary>
/// <Param name = "p_str_email"> input string </param>
/// <Returns> returns a boolean value. </returns>
Public bool validateemail (string p_str_email)
        {
Return regex. ismatch (p_str_email, @ "w + ([-+. '] w +) * @ w + ([-.] w + )*. w + ([-.] w + )*");
        }

 

Sixth: verify that the input string is a network address. Verify that the input string is a network address. // <summary>
/// Verify whether the input string is a network address

/// </Summary>
/// <Param name = "p_str_naddress"> input string </param>
/// <Returns> returns a boolean value. </returns>
Public bool validatenaddress (string p_str_naddress)
        {
Return regex. ismatch (p_str_naddress, @ "http (s )? : // ([W-] +.) + [w-] + (/[w -./? % & =] *)? ");
        }

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.