Common Regular Expression verification classes

Source: Internet
Author: User

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]) $");
}
 
}  
}  

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.