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 -./? % & =] *)? ");
}