The verification problem encountered in the project a few days ago, because it is not suitable for using verification controls, so I had to write a verification method and paste it on...
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
// Zoser
Namespace MDA
{
/// <Summary>
/// Summary of datacheckrule
///
/// Data check rules
/// </Summary>
Public class datacheckrule
{
Public datacheckrule ()
{
//
// Todo: add the constructor logic here
//
}
# Region // empty check of data items when new data is inserted into the database
///
/// <Summary>
/// String
/// </Summary>
Public String strinsertecheck (string Str)
{
If (STR = "")
{
Return "@@";
}
Else
{
Return STR;
}
}
/// <Summary>
/// Datatime
/// </Summary>
/// <Param name = "DT"> </param>
/// <Returns> </returns>
Public datetime dtinsertecheck (string Str)
{
System. text. regularexpressions. regEx reg1 = new system. text. regularexpressions. regEx (@ "^ (\ D {2} ([02468] [048]) | ([13579] [26]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (\ D {2} ([02468] [1235679]) | ([13579] [01345789]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (\ s (0? [1-9]) | (1 [0-2]) \ :( [0-5] [0-9]) (\ s) | (\ :( [0-5] [0-9]) \ s) ([am | Pm | am | PM] {2, 2 })))? $ ");
If (reg1.ismatch (STR ))
{
Return convert. todatetime (STR );
}
Else
{
Return convert. todatetime ("1900-01-01 ");
}
}
/// <Summary>
/// Int
/// </Summary>
/// <Param name = "I"> </param>
/// <Returns> </returns>
Public int intinsertecheck (string Str)
{
System. Text. regularexpressions. RegEx reg1 = new system. Text. regularexpressions. RegEx (@ "^ [-]? \ D + [.]? \ D * $ ");
If (reg1.ismatch (STR ))
{
Return convert. toint32 (STR );
}
Else
{
Return 9999;
}
}
/// <Summary>
/// Float
/// </Summary>
/// <Param name = "F"> </param>
/// <Returns> </returns>
Public float floatinsertecheck (string Str)
{
System. Text. regularexpressions. RegEx reg1 = new system. Text. regularexpressions. RegEx (@ "^ -? ([1-9] \ D * \. \ D * | 0 \. \ D * [1-9] \ D * | 0? \. 0 + | 0) $ ");
If (reg1.ismatch (STR ))
{
Return convert. tosingle (STR );
}
Else
{
Return 9999.9999f;
}
}
# Endregion
}
}