# Region verified email address
/** // <Summary>
/// Verify the email address
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool isemail (string source)
{
Return RegEx. ismatch (source, @ "^ [A-Za-z0-9] ([_ \. \-]? [A-zA-Z0-9] +) *) @ ([A-Za-z0-9] +) ([\. \-]? [A-zA-Z0-9] +) *) \. ([A-Za-Z] {2,}) $ ", regexoptions. ignorecase );
}
Public static bool hasemail (string source)
{
Return RegEx. ismatch (source, @ "[A-Za-z0-9] ([_ \. \-]? [A-zA-Z0-9] +) *) @ ([A-Za-z0-9] +) ([\. \-]? [A-zA-Z0-9] +) *) \. ([A-Za-Z] {2,}) ", regexoptions. ignorecase );
}
# Endregion
# Region verification URL
/** // <Summary>
/// Verify the URL
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool isurl (string source)
{
Return RegEx. ismatch (source, @ "^ (File | gopher | news | NNTP | Telnet | HTTP | FTP | HTTPS | ftps | SFTP )://) | (www \.)) + ([a-zA-Z0-9 \. _-] + \. [A-Za-Z] {2, 6}) | ([0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {}) (/[a-zA-Z0-9 \ & amp; % _\. /-~ -] *)? $ ", Regexoptions. ignorecase );
}
Public static bool hasurl (string source)
{
Return RegEx. ismatch (source, @ "(File | gopher | news | NNTP | Telnet | HTTP | FTP | HTTPS | ftps | SFTP): //) | (www \.)) + ([a-zA-Z0-9 \. _-] + \. [A-Za-Z] {2, 6}) | ([0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {}) (/[a-zA-Z0-9 \ & amp; % _\. /-~ -] *)? ", Regexoptions. ignorecase );
}
# Endregion
# Region verification date
/** // <Summary>
/// Verification date
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool isdatetime (string source)
{
Try
{
Datetime time = convert. todatetime (source );
Return true;
}
Catch
{
Return false;
}
}
# Endregion
# Region verification mobile phone number
/** // <Summary>
/// Verify the mobile phone number
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool ismobile (string source)
{
Return RegEx. ismatch (source, @ "^ 1 [35] \ D {9} $", regexoptions. ignorecase );
}
Public static bool hasmobile (string source)
{
Return RegEx. ismatch (source, @ "1 [35] \ D {9}", regexoptions. ignorecase );
}
# Endregion
# region verification IP address
/** //
// verification IP address
///
///
///
Public static bool isip (string source)
{< br> return RegEx. ismatch (source, @ "^ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [0-9]) $ ", regexoptions. ignorecase);
}< br> Public static bool hasip (string source)
{< br> return RegEx. ismatch (source, @ "(25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [0-9]) ", regexoptions. ignorecase);
}< BR ># endregion
# Region verify ID card validity
/** // <Summary>
/// Verify whether the ID card is valid
/// </Summary>
/// <Param name = "ID"> </param>
/// <Returns> </returns>
Public static bool isidcard (string ID)
{
If (Id. Length = 18)
{
Bool check = isidcard18 (ID );
Return check;
}
Else if (Id. Length = 15)
{
Bool check = isidcard15 (ID );
Return check;
}
Else
{
Return false;
}
}
Public static bool isidcard18 (string ID)
{
Long n = 0;
If (Long. tryparse (ID. remove (17), out n) = false | n <math. pow (10, 16) | long. tryparse (ID. replace ('x', '0 '). replace ('x', '0'), out n) = false)
{
Return false; // digit Verification
}
String address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62X15x33x42X51X63x21x34X43x52x64x65x71x81x82x91 ";
If (address. indexof (Id. Remove (2) =-1)
{
Return false; // province Verification
}
String birth = ID. substring (6, 8). insert (6, "-"). insert (4 ,"-");
Datetime time = new datetime ();
If (datetime. tryparse (birth, out time) = false)
{
Return false; // birthday Verification
}
String [] arrvarifycode = (", 0, x, 9, 8, 4,"). Split (',');
String [] Wi = (","). Split (',');
Char [] Ai = ID. Remove (17). tochararray ();
Int sum = 0;
For (INT I = 0; I <17; I ++)
{
Sum + = int. parse (WI [I]) * Int. parse (Ai [I]. tostring ());
}
Int y =-1;
Math. divrem (sum, 11, out y );
If (arrvarifycode [y]! = ID. substring (17, 1). tolower ())
{
Return false; // Verification Code
}
Return true; // conforms to GB11643-1999 standards
}
Public static bool isidcard15 (string ID)
{< br> long n = 0;
If (Long. tryparse (ID, out n) = false | n {< br> return false; // digital verification
}< br> string address = "11x22x35x44x53x12x23x36x45x54x13x31x37X46x61x14x32x41x50x62X15x33x42X51X63x21x34X43x52x64x65x71x81x82x91 ";
If (address. indexof (ID. remove (2) =-1)
{< br> return false; // province verification
}< br> string birth = ID. substring (6, 6 ). insert (4 ,"-"). insert (2, "-");
datetime time = new datetime ();
If (datetime. tryparse (birth, out time) = false)
{< br> return false; // birthday verification
}< br> return true; // meets the 15-digit ID card Standard
}< BR ># endregion
# Whether region is int type
/** //
// whether it is int type
//
//
//
Public static bool isint (string source)
{< br> RegEx = new RegEx (@ "^ (-) {0, 1} \ D + $");
If (RegEx. match (source ). success)
{< br> If (Long. parse (source)> 0x7fffffffl) | (Long. parse (source) <-2147483648l)
{< br> return false;
}< br> return true;
}< br> return false;
}< BR ># endregion
# region: Check whether the length of a string contains two Chinese characters in a limit.
/** ///
// check the string. is the length of a string between two Chinese characters
///
///
// greater than or equal to
// less than or equal to
//
Public static bool islengthstr (string source, int begin, int end)
{< br> int length = RegEx. replace (source, @ "[^ \ x00-\ xFF]", "OK "). length;
If (length <= begin) & (length> = END)
{< br> return false;
}< br> return true;
}< BR ># endregion
# Is region a Chinese phone number in the format of 010-85849685?
/** // <Summary>
/// Is it a Chinese phone number, in the format of 010-85849685
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool istel (string source)
{
Return RegEx. ismatch (source, @ "^ \ D {3, 4 }-? \ D {6, 8} $ ", regexoptions. ignorecase );
}
# Endregion
# Region zip code 6 digits
/** // <Summary>
/// Zip code 6 digits
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool ispostcode (string source)
{
Return RegEx. ismatch (source, @ "^ \ D {6} $", regexoptions. ignorecase );
}
# Endregion
# Region Chinese
/** // <Summary>
/// Chinese
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool ischinese (string source)
{
Return RegEx. ismatch (source, @ "^ [\ u4e00-\ u9fa5] + $", regexoptions. ignorecase );
}
Public static bool haschinese (string source)
{
Return RegEx. ismatch (source, @ "[\ u4e00-\ u9fa5] +", regexoptions. ignorecase );
}
# Endregion
# Region check whether it is a normal combination of letters, numbers, and underscores
/** // <Summary>
/// Check whether a combination of letters, numbers, and underscores is normal.
/// </Summary>
/// <Param name = "Source"> </param>
/// <Returns> </returns>
Public static bool isnormalchar (string source)
{
Return RegEx. ismatch (source, @ "[\ W \ D _] +", regexoptions. ignorecase );
}
# Endregion