Using system;
Using system. Web;
Using system. text;
Using system. Web. UI. webcontrols;
Using system. Text. regularexpressions;
Public class validatehelper
{
Private Static RegEx regnumber = new RegEx ("^ [0-9] + $ ");
Private Static RegEx regnumbersign = new RegEx ("^ [+-]? [0-9] + $ ");
Private Static RegEx regdecimal = new RegEx ("^ [0-9] + [.]? [0-9] + $ ");
Private Static RegEx regdecimalsign = new RegEx ("^ [+-]? [0-9] + [.]? [0-9] + $ ");
Private Static RegEx regemail = new RegEx ("^ [\ W-] + @ [\ W-] + \\. (COM | net | org | Edu | mil | TV | biz | info) $ ");
Private Static RegEx regchzn = new RegEx ("[\ u4e00-\ u9fa5]");
Private Static RegEx regtell = new RegEx ("^ ([0-9] {3.4}-) | [0-9 }-)? [0-9] {7, 8} $ ");
Private Static RegEx regsend = new RegEx ("[0-9] {1} ([0-9] +) {5 }");
Private Static RegEx regurl = new RegEx ("^ [A-Za-Z] +: // (\ W + (-\ W + )*)(\\. (\ W + (-\ W + )*))*(\\? \ S *)? | [A-Za-Z] + ://((? :(? : 25 [0-5] | 2 [0-4] \ d | [01]? \ D? \ D) \.) {3 }(? : 25 [0-5] | 2 [0-4] \ d | [01]? \ D? \ D) $ ");
Private Static RegEx regmobilephone = new RegEx ("^ 13 | 15 | 18 [0-9] {9} $ ");
Private Static RegEx regmoney = new RegEx ("^ [0-9] + | [0-9] + [.]? [0-9] + $ ");
# Region numeric string check
/// <Summary>
/// Whether it is a numeric string
/// </Summary>
/// <Param name = "inputdata"> input string </param>
Public static bool isnumber (string inputdata)
{
If (! String. isnullorempty (inputdata ))
{
Match m = regnumber. Match (inputdata );
Return M. success;
}
Else
{
Return false;
}
}
/// <Summary>
/// Whether a numeric string can contain positive and negative numbers
/// </Summary>
/// <Param name = "inputdata"> input string </param>
Public static bool isnumbersign (string inputdata)
{
Match m = regnumbersign. Match (inputdata );
Return M. success;
}
/// <Summary>
/// Whether it is a floating point
/// </Summary>
/// <Param name = "inputdata"> input string </param>
Public static bool isdecimal (string inputdata)
{
Match m = regdecimal. Match (inputdata );
Return M. success;
}
/// <Summary>
/// Whether the floating point can contain positive and negative numbers
/// </Summary>
/// <Param name = "inputdata"> input string </param>
Public static bool isdecimalsign (string inputdata)
{
Match m = regdecimalsign. Match (inputdata );
Return M. success;
}
# Endregion
# Region Chinese Detection
/// <Summary>
/// Check for Chinese Characters
/// </Summary>
Public static bool ishaschzn (string inputdata)
{
Match m = regchzn. Match (inputdata );
Return M. success;
}
# Endregion
# Region email address
/// <Summary>
/// Whether the email address is used
/// </Summary>
/// <Param name = "inputdata"> input string </param>
Public static bool isemail (string inputdata)
{
Match m = regemail. Match (inputdata );
Return M. success;
}
# Endregion
# Region phone, zip code, network address, mobile phone number, price
/// <Summary>
/// Verify the phone number
/// </Summary>
Public static bool isphone (string inputdate)
{
If (! String. isnullorempty (inputdate ))
{
Match m = regtell. Match (inputdate );
Return M. success;
}
Else
{
Return false;
}
}
/// <Summary>
/// Whether it is a zip code
/// </Summary>
Public static bool issend (string inputdate)
{
If (! String. isnullorempty (inputdate ))
{
Match m = regsend. Match (inputdate );
Return M. success;
}
Else
{
Return false;
}
}
/// <Summary>
/// Whether it is a network address
/// </Summary>
Public static bool isurl (string inputdate)
{
Match m = regurl. Match (inputdate );
Return M. success;
}
/// <Summary>
/// Whether it is a mobile phone number
/// </Summary>
Public static bool ismobilephone (string inputdate)
{
Match m = regmobilephone. Match (inputdate );
Return M. success;
}
/// <Summary>
/// Whether it is a price
/// </Summary>
Public static bool ismoney (string inputdate)
{
Match m = regmoney. Match (inputdate );
Return M. success;
}
# Endregion
# Whether region is in the Time Format
/// <Summary>
/// Determine whether a string is in time format
/// </Summary>
/// <Param name = "inputdata"> input string </param>
/// <Returns> </returns>
Public static bool isdatetime (string inputdata)
{
Try
{
Convert. todatetime (inputdata );
Return true;
}
Catch
{
Return false;
}
}
# Endregion
}