Link to home
Start Free TrialLog in
Avatar of ayeshanasreen
ayeshanasreen

asked on

Best way of Handling Field Level Validations

hi all

I have many forms which requires Only Numeric, Only Alphabetic, BothAlpha Numeric and No spl. characters.

Which is the best suitable approach to validate the form fields before storing it into the database.

Is it possible to write a generalized routine for handling all the forms in common.

do suggestions needed.

thanks
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

For fields to be only numeric of alpha, you better validate on a per-character basis (using the KeyPress event).

For specific field validation (mandatory, minimum length, ...), you better validate in the LostFocus event of each controls.

For referential validation (if FieldA is empty then FieldB must not be empty, ...), you better use form validation (in your save button click event for example).

Using appropriate controls helps you a lot (like a mask edit box, date time picker, ...).
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can roll-your-own textbox controls or use third-party controls to restrict your users' input.  

My saying to my VB students:
"The best validation is the one that requires no code, because the user is limited to entering only valid data."
Avatar of priya_pbk
priya_pbk

>>What I had done to handle this is to have a user-control that added a DataType property.  With this, I defined the type of valid data allowed in the field, such as numeric, integer, alpha-only, "sentence", alpha-numeric, e-mail, etc.  When the field is created, define the DataType property and the validation can be done during data entry.<<

If you are interested to create a usercontrol then check out the "PART 2" this link:

http://216.26.168.92/vbworld/file.aspx?tag=activex

It will surely help you to create your own control, without having actually to make validation for each TextBox

-priya

This question appears to be abandoned. A question regarding it will be left in the CleanUp
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <emoreau>.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.