Introduction
This article demonstrates a control that combines textbox, multi-validation and response labels in one control. Allows textbox to do self checking and self error response messages. Control can protect against SQL injection attacks and client script attacks with a special character set property. You can also specify custom character sets for your control with the chars
property. This control also includes many validation types to choose from: NONE
, USERDEFINED
, EMAIL
, URL
, ZIPCODE
, PHONE
, INTERNATIONALPHONE
, DATE
, ADVANCEDDATE
, UKDATE
, IPADDRESS
, UKPOSTALCODE
, SSN
, CREDITCARD
, PASSWORD
, PERCENTAGE
and GUID
. Control can also run user defined validation types. Control also has built in range validation, bad word filter, required validator and comparison validator.
Language:
VB.NET and ASP.NET (For all you C# coders, who get paid more than VB.NET programmers!!! :P~)
Version:
1.0 - Final version.
How to use
Compile code into a .NET DLL assembly and put into your website home (bin) folder. Then add the following code to your ASP.NET webpage:
<%@ Register TagPrefix="Hive" NameSpace="Hive.Controls" Assembly="Hive"%>
Then add the textbox
control in your form:
<Hive:textbox id="textbox1" runat="server" req="True"/>
Classes |
Class Name |
Description |
Hive.Controls - Namespace
Description - Complex custom textbox user control. |
HiveException |
For handling all Hive exceptions that can occur. Inherits ApplicationException |
textbox |
Hive multi-validating self textbox control. Inherits System.Web.UI.UserControl
Implements IValidator |
Properties |
Property Name |
Type |
Description |
Control validation properties |
IsValid |
Boolean |
Checks to see if this control is valid and returns it to the page validation. |
ErrorMessage |
String |
The error message from the validator validation. |
Type |
ValidationMode |
For setting the type of validation to do. (Enumeration: ValidationMode ) Types of validation - NONE | USERDEFINED | EMAIL | URL | ZIPCODE | PHONE | INTERNATIONALPHONE | DATE | ADVANCEDDATE | UKDATE | IPADDRESS | UKPOSTALCODE | SSN | CREDITCARD | PASSWORD | PERCENTAGE | GUID |
Compare |
CompareMode |
For setting the compare mode type of the textbox. |
RangeType |
RangeMode |
For setting the range type of the properties MinimumValue and MaximumValue . |
MinimumValue |
String |
For setting the start parameter for range validation. |
MaximumValue |
String |
For setting the end parameter for range validation. |
CustomCharsError |
String |
For setting a custom CharsetMode regular expression error message. |
CustomChars |
String |
For setting a custom CharsetMode regular expression. |
CustomRegExp |
String |
For setting the custom regular expression for the user-defined ValidationMode . |
CustomError |
String |
For setting the custom error message for a user-defined ValidationMode . |
CreditCardType |
String |
A credit card type ReadOnly property of CardType enumeration. |
BadWords |
Boolean |
To test textbox text for bad words and return an error. |
Chars |
CharsetMode |
For setting the type of characters allowed by the textbox. (Enumeration: CharsetMode ) Types of characters - NONE | USERDEFINED | ALL | NONHTML | NOQUOTES | NODOUBLEQUOTES | ALPHA | ALPHANUMERIC | NUMERIC |
Req |
Boolean |
Check to see if textbox is required field. |
Max |
Integer |
For setting the textbox max character length. |
Min |
Integer |
For setting the textbox min character length. |
Extended Textbox Control Properties |
onSelect |
String |
For setting the textbox onSelect property. |
onMouseUp |
String |
For setting the textbox onMouseUp property. |
onMouseOver |
String |
For setting the textbox onMouseOver property. |
onMouseOut |
String |
For setting the textbox onMouseOut property. |
onMouseMove |
String |
For setting the textbox onMouseMove property. |
onMouseDown |
String |
For setting the textbox onMouseDown property. |
onKeyUp |
String |
For setting the textbox onKeyUp property. |
onKeyPress |
String |
For setting the textbox onKeyPress property. |
onKeyDown |
String |
For setting the textbox onKeyDown property. |
onFocus |
String |
For setting the textbox onFocus property. |
onDblClick |
String |
For setting the textbox onDblClick property. |
onClick |
String |
For setting the textbox onClick property. |
onChange |
String |
For setting the textbox onChange property. |
onBlur |
String |
For setting the textbox onBlur property. |
Control Style Properties |
Style1 |
String |
For setting the textbox CSS style. |
Style2 |
String |
For setting the error label CSS style. |
Style3 |
String |
For setting the display label CSS style. |
Style4 |
String |
For setting the CSS style of the required symbol asterisk. |
Table |
Boolean |
Boolean property for creating tables around textbox and labels. |
ReqSymbol |
Boolean |
Adds an asterisk to the end of the textbox. |
Label |
String |
For setting the label message of the textbox control. |
Control Standard Properties |
Width |
Integer |
For setting the textbox width. |
Height |
Integer |
For setting the textbox height. |
ID |
String |
For setting the textbox ID. |
ID2 |
String |
For setting the compare textbox ID. |
ReadOnly |
Boolean |
For setting the textbox ReadOnly property. |
Text |
String |
For setting the text value of the textbox control. |
Value |
String |
The value of the textbox control. |
TextMode |
TextBoxMode |
For setting the text mode of the textbox. (Enumeration: TextBoxMode ) Types of modes - SINGLELINE | MULTILINE | PASSWORD . |
ProperName |
String |
For setting a proper name for the textbox control. |
ProperName2 |
String |
For setting the proper name of the compare control. |
Enumerations |
Enum const |
Description |
CharsetMode - Enumeration
Description - An enumeration of different types of allowed character sets. |
NONE |
Allows no characters to be used. |
USERDEFINED |
Allows developer to specify characters to be used. |
ALL |
Allows all characters to be used. |
NONHTML |
Allows all non HTML characters to be used. |
NOQUOTES |
Allows all characters except quotes to be used. |
NODOUBLEQUOTES |
Allows all characters except double quotes to be used. |
ALPHA |
Allows all alpha characters to be used only. |
ALPHANUMERIC |
Allows all alpha-numeric characters to be used only. |
NUMERIC |
Allows all numeric characters to be used only. |
ValidationMode - Enumeration
Description - An enumeration of different types of validations. |
NONE |
Allows no validation type. |
USERDEFINED |
Allows developer to specify own validation regular expression type. |
EMAIL |
Allows email validation type. |
URL |
Allows URL validation type. |
ZIPCODE |
Allows zip code validation type. |
PHONE |
Allows phone number validation type. |
INTERNATIONALPHONE |
Allows international phone number validation type. |
DATE |
Allows date validation type. |
ADVANCEDDATE |
Allows advanced date validation type. |
UKDATE |
Allows UK date validation type. |
IPADDRESS |
Allows IP address validation type. |
UKPOSTALCODE |
Allows UK postal code validation type. |
SSN |
Allows social security number validation type. |
CREDITCARD |
Allows credit card validation type. |
PASSWORD |
Allows password validation type. |
PERCENTAGE |
Allows percentage validation type. |
GUID |
Allows GUID validation type. |
CompareMode - Enumeration
Description - An enumeration of different types of compare modes. |
NONE |
No compare mode used. |
EQUAL |
Compare mode set to equal. |
CASEEQUAL |
Compare mode set to case equal. |
NOTEQUAL |
Compare mode set to not equal. |
CardType - Enumeration
Description - An enumeration of different types of credit cards. |
NONE |
No credit card type specified. |
MASTERCARD |
MasterCard card type. |
VISA |
Visa card type. |
AMEX |
American Express card type. |
DISCOVER |
Discover card type. |
DINERSCLUB |
Diners Club card type. |
ENROUTE |
EnRoute card type. |
JCB |
JCB card type. |
RangeMode - Enumeration
Description - An enumeration of types for setting range properties to that type. |
NONE |
Sets the range mode to nothing. |
CURRENCY |
Sets the range mode type to currency. |
DATE |
Sets the range mode type to Date . |
DOUBLE |
Sets the range mode type to Double . |
INTEGER |
Sets the range mode type to Integer . |
STRING |
Sets the range mode type to String . |
Conclusion
Well, I am finally finished with my hive textbox control. It seemed like it was going to take an eternity to finish, well at least the document.
License:
Free to use and modify as long as header stays in place. Users must also send an email to the author's email address stating where they are using the code. If any modifications are made to this assembly, users must email changes to author's email address.
Terms and Conditions For Use, Copy, Distribution and Modification:
THIS CODE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.