I was doing my usual programming, and one day, I was stuck in a big form that had too many textbox controls with many validations. I had a hard day putting all the things together on that page. I was a bit confused why Microsoft did not provide validations with the textbox itself. So, I have done that here. Now, nobody will have problems as I faced recently. Please send me any bug reports or suggestions for improving the textbox. This textbox is named as Zatak as I am a very big fan of the Zatak perfume. This textbox is like a simple textbox but it contains a lot of validation options which you can set using simple click and keystrokes. I am providing more details to you below. I am very thankful to Click2Install for providing me the initial framework. The source code is attached with the article and the zip file also contains a small demo of what the control can do.
Using the component
There are different parts to the textbox control. The first part is the General Settings which are settings regarding the general validation control shown as above. It contains the focus on error, client script, validator display style, and method to show the validation. Currently, it supports text and icon. You can include other methods if you like.
Required Validation Settings
The first validation is required validation. If you want this textbox as required, then tick on the checkbox and write the message into the textbox which you want to show to the user.
Regular Expression Validation Settings
The second validation is regular expression validation. If you want this textbox to behave as some fixed type then select it from the combobox. You can give different settings as per the selection. Like for
alphanumericwithspecialchar, you will get a textbox to enter special characters. For
decimal, you will be prompted for digits after decimal. And there is one option
Custom where you can provide your own regular expression.
Range Validation Settings
The third validation is range validation. If you want this textbox to include range validation, then tick this option. You can give different settings similar to the range validator.
Compare Validation Settings
The fourth validation is compare validation. If you want this textbox to include compare validation then tick this option. You can give different settings similar to the compare validator..
Custom Validation Settings
The fifth validation is custom validation. If you want to make a server function for validation, then implement the
Points of Interest
The first thing is sometimes there is memory problems in my Visual Studio 2005. I have put code to dispose the things that are allocated. But still if you find anything for improvements, then please let me know. All validations contain their own messages.
Currently there is a problem with the regular expression for date validation. I took it from a regular expression library site. It wass given for DD/MM/YYYY. But because I could not convert it to MM/DD/YYYY, I used another regular expression for MM/DD/YYYY. In that regular expression, 1/1/1 is not validated as date.
If you need anything regarding the code or its logic, please comment on this article.
If you find it useful or great then please rate this article a 5 :).
I have used the internal validators of ASP.NET 2.0 to build the validators behind the scenes.
And yes, do visit my Blog for upgrades and blogs about ASP.NET. I have recently started it and will post interesting article links, posts, snippets, and tools, and many other things that can save you time. So please subscribe to the RSS right now.
- Version 1.0 - Initial release.