From TextBox, join the function of regular expression verification data, there should be some use, I will submit it in the 9CBS sharing software, and interested buddies can go see. Here is the source code, at least let me look like this, ^ _ ^
File: //RegexTextBox.cs
/ **
* Created on February 17, 2004
*
Anyone can use this control free of charge, and get the source code for this control.
*
Please refer to the regular expression
MSDN
Or related books
* /
// Import the .NET class library used by the program
Using system;
Using system.drawing;
Using system.windows.forms;
Using system.text.regularExpressions;
// Name the space regexeditor, will continue to expand ....
Namespace regexeditor
{
/ ** RegextExtBox inherits from TextBox control
* The data can be valid for data by regular expressions
* /
Public Class Regextbox: System.Windows.Forms.TextBox
{
Private string strregex; // Regular expression for verification
Private string strrifyerror; // Tips for checking errors
Private bool bisverifysuccess; // is inspected successfully
Private bool bisdisplayerror; // Whether it is displayed
PRIVATE BOOL BTOVERIFY; / / Whether to check
// Property: Regular expression for verification
Public String RegexString
{
get
{
Return Strregex;
}
set
{
Strregex = value;
}
}
// Property: Tips for testing errors
Public String VerifyErRorstring
{
get
{
Return strVerifyerror;
}
set
{
StrVerifyerror = value;
}
}
// Attribute: Whether the inspection is successful
Public Bool IsverifySuccess
{
get
{
Return Bisverifysuccess;
}
set
{
BiSverifysuccess = value;
}
}
// Attribute: Whether to display a verification error
Public Bool IsDisplayError
{
get
{
Return bisdisplayerror;
}
set
{
BiSDisplayError = Value;
}
}
Public Bool Toverify
{
get
{
Return bturn;
}
set
{
Btoverify = value;
}
}
//Constructor
Public regexTextBox ()
{
InitializationComponent ();
}
// Initialization variables and control properties
void initializecomponent ()
{
RegexString = ""
VerifyerRorstring = ""
Isverifysuccess = true;
IsdisplayError = false;
TOVERIFY = FALSE;
THIS.NAME = "regextextbox";
THIS.VALIDATING = New System.comPonentModel.canceleventHandler (this.onvalidatingdata);
// Private process: verify data
Private bool verifydata ()
{
IsverifySuccess = regex.ismatch (this.text, regexstring);
Return isverifysuccess;
}
// Event processing function: verification data
Private void onvalidatingdata (Object Sender, System.componentmodel.canceleventargs E)
{
IF (! Toverify) / / Do not need to verify directly
{
e.cancel = false;
Return;
}
IF (! VerifyData ()) // The verification is incorrect ..
{
if (this.isdisPlayError) / / Requires the verification error message..
{
Messagebox.show (VerifyerRorstring, "Warning:");
}
ELSE // requires no verification error tips..
{
THIS.SELECTALL ();
} // end if
e.cancel = true;
}
ELSE // The verification is correct..
{
e.cancel = false;
} // end if
}
} // End Class
} // end namespace