[★]. Net c/s how to use the regular expression

Source: Internet
Author: User

class vilcontrol
{< br> ///


/// determine whether it is empty
///
//< returns> if it is null, false is returned.
Public static bool isnull (string syllable)
{< br> If (syllable. trim () = "") // determines whether the input is null
{< br> return false;
}

Return true;
}

/// <Summary>
/// Verify that the string is valid
/// </Summary>
/// <Param name = "syllable"> string to be verified </param>
/// <Param name = "RegEx"> Regular Expression </param>
/// <Returns> </returns>
Private Static bool regexoperation (string syllable, string RegEx)
{
// Enumeration type of the Regular Expression
System. Text. regularexpressions. regexoptions Options = (
(System. Text. regularexpressions. regexoptions. ignorepatternwhitespace |
System. Text. regularexpressions. regexoptions. multiline) |
System. Text. regularexpressions. regexoptions. ignorecase );

// Load the regular expression to the enumerated type
System. Text. regularexpressions. RegEx Reg = new system. Text. regularexpressions. RegEx (RegEx, options );

// Return the verification result
Return Reg. ismatch (syllable );
}

/// <Summary>
/// Determine whether the password exceeds the length (6 ~ 16)
/// </Summary>
/// <Returns> If the value is too long, false is returned. </returns>
Public static bool islong (string syllable)
{
If (! Isnull (syllable) // determines whether the input is null.
{
Return false;
}

Bool problem = true;

If (syllable. length> 16 | syllable. length <6) // determine whether the password is consistent with the number of digits
{< br> return problem = false;
}< br> return problem;
}

//


// age (length/integer) (1 ~ 110)
//
// false is returned incorrectly
Public static bool isage (string syllable)
{< br> If (! Isnull (syllable) // determines whether the input is null
{< br> return false;
}

If (convert. toint32 (syllable)> 110 | convert. toint32 (syllable) <1) // judge the length
{
Return false;
}

String RegEx = "^ [0-9] {1,} $"; // The value is a number.

Return regexoperation (syllable, RegEx );
}

//


// check whether the phone number meets the requirements (3)
///
/// false is returned if the response does not match
Public static bool isphone (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

// Regular Expression
String RegEx = @ "\ D {3}-\ D {8} | \ D {4}-\ D {7} | \ D {11 }";

// Return the verification result
Return regexoperation (syllable, RegEx );
}

///


// determine whether the date meets the requirements)
///
/// false is returned if the response does not match
Public static bool isday (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

// Regular Expression
String RegEx = @ "^ (1 [6-9] | [2-9] \ D) \ D {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ D) \ D {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ D) \ D {2 }) -0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ D) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $ ";

// Return the verification result
Return regexoperation (syllable, RegEx );
}

///


// whether the email meets the email requirements
///
// false is returned for non-conformities
Public static bool ise_mail (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

// Regular Expression
String RegEx = @ "\ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W + )*";

// Return the verification result
Return regexoperation (syllable, RegEx );
}

///


// a string consisting of a number and 26 English letters or underscores
///
///
//
Public static bool strverify (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

string RegEx = @ "^ \ W + $";
return regexoperation (syllable, RegEx );
}

///


/// only 1 ~ Positive number of three decimal places
///
///
///
Public static bool numdec (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

// Regular Expression
String RegEx = @ "^ [0-9] + (. [0-9] {1, 3 })? $ ";

// Return the verification result
Return regexoperation (syllable, RegEx );
}

//


// It must start with a letter and be 6 to 18 characters in length, only characters, numbers, and underscores are allowed.
///
///
// /
Public static bool strverifystart (string syllable)
{< br> // determines whether the input is empty.
If (! Isnull (syllable)
{< br> return false;
}

// Regular Expression
String RegEx = @ "^ [A-Za-Z] \ W {5, 17} $ ";

// Return the verification result
Return regexoperation (syllable, RegEx );
}
}

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.