Hive Multi-Validating Self Textbox Control






3.95/5 (9 votes)
Jun 1, 2004
6 min read

111709

1570
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.
|
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.