Some common Regular Expression verification classes collected:
Using System;
Using System. Text. regularexpressions;
Namespace Commontools
{
/**/ /**/ /**/ /// <Summary>
///A summary of regexlib.
/// </Summary>
Public Class Regexlib
{
// Verify email address
Public Static Bool Isvalidemail ( String Strin)
{< br> // return true if strin is in valid e-mail format.
return RegEx. ismatch (strin, @ " ^ ([\ W-\.] +) @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\.) | ([\ W-] + \.) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (\]?) $ " );
}
// The date format of DD-mm-yy replaces the date format of mm/DD/yy.
Public Static String Mdytodmy (string input)
{
ReturnRegEx. Replace (input,"\ B (? \ D {1, 2 })/(? \ D {1, 2 })/(? \ D {2, 4}) \ B","$ {Day}-$ {month}-$ {year}");
}
// Verify whether it is decimal
Public Static Bool Isvaliddecimal ( String Strin)
{
ReturnRegEx. ismatch (strin,@"[0]. \ D {1, 2} | [1]");
}
// Verify the phone number
Public Static Bool Isvalidtel ( String Strin)
{
ReturnRegEx. ismatch (strin,@"(\ D + -)? (\ D {4 }-? \ D {7} | \ D {3 }-? \ D {8} | ^ \ D {7, 8}) (-\ D + )?");
}
// Verification year month day
Public Static Bool Isvaliddate ( String Strin)
{
ReturnRegEx. ismatch (strin,@"^ 2 \ D {3 }-(? : 0? [1-9] | 1 [0-2])-(? : 0? [1-9] | [1-2] \ d | 3 [0-1]) (? : 0? [1-9] | 1 \ d | 2 [0-3]) :(? : 0? [1-9] | [1-5] \ D ):(? : 0? [1-9] | [1-5] \ D) $");
}
// Verify suffix
Public Static Bool Isvalidpostfix ( String Strin)
{
ReturnRegEx. ismatch (strin,@"\.(? I: GIF | JPG) $");
}
// Verify whether the character range is 4 to 12
Public Static Bool Isvalidbyte ( String Strin)
{
ReturnRegEx. ismatch (strin,@"^ [A-Z] {4, 12} $");
}
// Verify IP Address
Public Static Bool Isvalidip ( String Strin)
{
ReturnRegEx. ismatch (strin,@"^ (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) \. (\ D {1, 2} | 1 \ D \ d | 2 [0-4] \ d | 25 [0-5]) $");
}
}
}