C # Form Verification

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace bookan. Others
{
Class vli
{
/// <Summary>
/// Determine whether it is empty
/// </Summary>
/// <Returns> null returns false </returns>
Public static bool isnull (string syllable)
{
If (syllable. Trim () = "") // determines whether the input is empty.
{
Return false;
}

Return true;
}

/// <Summary>
/// Judge non-special characters
/// </Summary>
/// <Param name = "syllable"> Verification string </param>
/// <Returns> null returns false </returns>
Public static bool isespecial (string syllable)
{
String RegEx = "[\ u4e00-\ u9fa5]";

Return regexoperation (syllable, RegEx );

}

/// <Summary>
/// Non-numeric
/// </Summary>
/// <Param name = "syllable"> Verification string </param>
/// <Returns> null returns false </returns>
Public static bool isnumber (string syllable)
{
String RegEx = "^ [0-9] {1,} $ ";
// String RegEx = @ "^ [1-9] $ | ^ 1 [0-2] $ ";
Return regexoperation (syllable, RegEx );
}

/// <Summary>
/// Name Length (20/50/100)
/// </Summary>
/// <Param name = "syllable"> Verification string </param>
/// <Returns> null returns false </returns>
Public static bool checknamelength (string syllable, int long)
{
Switch (long)
{
Case 20:
If (syllable. length> = 20) return false;
Break;
Case 50:
If (syllable. length> = 50) return false;
Break;
Case 100:
If (syllable. length> = 100) return false;
Break;
}

Return true;
}

# Region Non-English characters
/// <Summary>
/// Non-English characters
/// </Summary>
/// <Param name = "syllable"> Verification string </param>
/// <Returns> Verification Result </returns>
Public static bool isworld (string syllable)
{
String RegEx = "^ [A-Za-Z] + $ ";

Return regexoperation (syllable, RegEx );
}
# Endregion

/// <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 );
}

///


// 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 );
}

/// <Summary>
/// Regular Expression string
/// </Summary>
/// <Param name = "strverify"> </param>
/// <Returns> </returns>
Public static bool strverify (string syllable)
{
String RegEx = "[0-9] + $"; // a string consisting of a number and 26 letters
Return regexoperation (syllable, RegEx );
}

 

/// <Summary>
/// Regular Expression string
/// </Summary>
/// <Param name = "strverify"> </param>
/// <Returns> </returns>
Public static bool STR (string syllable)
{
String RegEx = @ "^ \ D + $"; // only numbers can be entered
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.