Click here to Skip to main content
15,867,686 members
Articles / Web Development / ASP.NET
Article

Hive Multi-Validating Self Textbox Control

Rate me:
Please Sign up or sign in to vote.
3.95/5 (11 votes)
31 May 20046 min read 110.9K   1.6K   39   14
A Multi-Validating Textbox Control for ASP.NET

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.

Code Description

Combines textbox and multi-validation in one control. Allows textbox to do self checking and self error response messages. Control can also protect against sql injection attacks and client script attacks. Textbox also can do credit card checking using the LUHN Formula Mod-10 check. Other validation types include PHONE, EMAIL, ZIP CODE, CREDIT CARD, URL, INTERNATIONAL PHONE, DATE, ADVANCED DATE, UK DATE, UK POSTAL CODE, SSN and IPADDRESS.

Version

1.0 beta (My Control is still in testing mode but seems almost bug free! But what code doesn't have bugs?)

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"/> 

Properties

Below is a list of properties and what they do.

Property Name Type Description
Control Properties
label string For setting the label message of the textbox control.
propername string For setting a proper name for the textbox control.
propername2 string For setting the proper name of the compare control.
type ValidationMode For setting the type of validation to do. (Enumeration:ValidationMode) Types of Validation - PHONE | EMAIL | ZIPCODE | CREDITCARD | URL | INTERNATIONALPHONE | DATE | ADVANCEDDATE | UKDATE | UKPOSTALCODE | SSN | IPADDRESS
badwords boolean To test textbox text for bad words and return an error.
textmode TextBoxMode For setting the textmode of the textbox. (Enumeration:TextBoxMode) Types of Modes - SINGLELINE | MULTILINE | PASSWORD
chars CharsetMode For setting the type of characters allowed by the textbox. (Enumeration:CharsetMode) Types of Characters - ALL | NONHTML | NOQUOTES | NODOUBLEQUOTES | ALPHA | ALPHANUMERIC | NUMERIC
req boolean Check to see if textbox is required field.
max string For setting the textbox max character length.
min string For setting the textbox min character length.
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.
width string For setting the controls width.
height string For setting the controls height.
id string For setting the textbox ID.
id2 string For setting the compare textbox ID.
text string For setting the text value of the textbox control.
ErrorMessage string The error message from the ivalidator validation.
IsValid boolean Checks to see if this control is valid and returns it to the page validation.
Control Error Message Properties
Err_Type_URL string For setting the error message for the url type function.
Err_Type_UKPostalCode string For setting the error message for the uk postal code type function.
Err_Type_IPAddress string For setting the error message for the ip address type function.
Err_Type_Date_UK string For setting the error message for the uk date type function.
Err_Type_Date_Adv string For setting the error message for the advanced date type function.
Err_Type_Date string For setting the error message for the date type function.
Err_Type_Phone_Int string For setting the error message for the international phone type function.
Err_Type_SSN string For setting the error message for the social security number type function.
Err_CreditCard1 string For setting the error message for the credit card function.
Err_CreditCard2 string For setting the error message for the credit card function invalid.
Err_BadWords string For setting the error message for the bad word function.
Err_Required string For setting the error message for the required function.
Err_Min string For setting the error message for the min character function.
Err_Max string For setting the error message for the max character function.
Err_Chars string For setting the error message for the character set function.
Err_Type_Phone string For setting the error message for the phone type function.
Err_Type_Email string For setting the error message for the email type function.
Err_Type_Zip string For setting the error message for the zip code type function.
Err_Compare string For setting the error message for the compare function.
Property Name Type Description

Details

I built this user control because I was tired of writing so much repetitive code. It usually takes several lines of code to run validation on one textbox, but not now. I combined validation with a textbox control and made it accessible through properties of one control. Making for slimmer and easy to manage code. I also combined error label response messages built in. This allows users filling out a form to see their mistakes. I also added a label property to describe the textfield box. YES! All in one function.

My type property can run many validation type functions. I have creating many different types already: PHONE, EMAIL, ZIPCODE, CREDITCARD, URL, INTERNATIONALPHONE, DATE, ADVANCEDDATE, UKDATE, UKPOSTALCODE, SSN, IPADDRESS and so on. This makes it so neat to have these at your disposal at any time. My control Implements IValidator which allows me to use the isvalid and errormessage properties. Doing this allows me to control the page.isvalid property and change it for each control. So each control can do multiple validation. My control can check character length of both min and max. It can also check if a textfield is required.

My control can also check characters to make sure those characters are allowed. By setting the chars property character validation will occur: ALL, NONHTML, NOQUOTES, NODOUBLEQUOTES, ALPHA, ALPHANUMERIC, NUMERIC, etc. By controlling the characters you can protect against sql injection and client script attacks. You can also make sure your database doesn't get screwed up. HEHE ;)

My control has so many features in it that sometimes I forget I created it. LOL

Anyway I hope this has been a little help for you guys on how to do custom controls with custom validation. If you guys like my code let me know.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Codevendor
United States United States
Please visit my personal website https://codevendor.com for my latest codes and updates.

Comments and Discussions

 
GeneralFinal Version Done Pin
M@dHatter3-Jul-04 12:39
M@dHatter3-Jul-04 12:39 
GeneralFinal Version Pin
M@dHatter4-Jun-04 14:37
M@dHatter4-Jun-04 14:37 
GeneralRe: Final Version Pin
mdissel4-Jun-04 21:14
mdissel4-Jun-04 21:14 
GeneralRe: Final Version Pin
M@dHatter5-Jun-04 12:35
M@dHatter5-Jun-04 12:35 
GeneralRe: Final Version Pin
M@dHatter5-Jun-04 16:25
M@dHatter5-Jun-04 16:25 
I am currently adding in custom errors to help developers in using my control figure out what they are doing wrong.

Big Grin | :-D
Generalalign with other controls Pin
mdissel4-Jun-04 8:37
mdissel4-Jun-04 8:37 
GeneralRe: align with other controls Pin
M@dHatter4-Jun-04 12:42
M@dHatter4-Jun-04 12:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.