Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Developers,
Just for the performance of the project, where to validate the data??
Suppose i have a DATETIME column in the database.
Here i can put CHECK constraint to restrict the user to enter the INVALID date.
OR I can VALIDATE with the help of javascript at the client side.
OR I can VALIDATE at the server side.

Above all three my Questions are,
1. Is it good to put all three validations???
2. whats the use of validating at the DATABASE side then validating Client side?
All suggestion will be appreciable..
Posted
Updated 2-Apr-12 20:11pm
v2

Hi ,
The First line of defense is your interface so you should validate on the controls
1 - first using Javascript of course it will enhance your performance .
2 - in your code behind you have to check and validate in your data .
3 - the last line of your defense is your Database and it will be Disaster if someone not authorize reach to it .

Tip: your dealing with users imagine they are trying to destroy your application and you have to take care of them .

So the answer all .
Best regards
M.Mitwalli
 
Share this answer
 
All have there own importance
see
Client side validation is good with respect of performance but if a user disables JavaScript, then no validation will occur.

With server side validation, there are more return trips to the server which in turns uses more resources and slows down the site when a client side script could have done the validation without the server.
So
You need to do both, client side to provide a better user experience, and server side to be sure that the input you get is actually validated and not just supposedly validated by the client.
Database Constraints: Use Them or Lose Them?
 
Share this answer
 
v2
Comments
The Doer 3-Apr-12 2:30am    
Yeah absolutely,
But now my point of view is towards SQL validations..
We can use CHECK constraint also at database side.. If we can validate at client and server side,then what is the use of that CONSTRAINT in SQL SERVER??? And where this CHECK constraint is applicable??
uspatel 3-Apr-12 2:34am    
I think,If you are using server side validaion then you do not need check constraints.......
uspatel 3-Apr-12 2:45am    
see updated answer
The Doer 3-Apr-12 2:59am    
yeah thanks a its useful stuff:-)
uspatel 3-Apr-12 2:59am    
you are welcome...
Validating on Client side is better
because if you are using server side validation then entire data will be submitted to server and then the validation will be performed(Which is waste)

If you check at database side then also you need to establish connection to database and then you will come to know that format is wrong.

and Client side validations restrict the submission of data until you enter correct format.

So go with Client side validations.

[EDIT]-------
Yes there are chances that a user can disable javascript.
So perform both ways as said by Uma sankar to get better Validation of your fields.

Go through this link so that you will get some info regarding check constraint

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_constraints.htm#i1006547[^]
 
Share this answer
 
v3
Comments
uspatel 3-Apr-12 2:17am    
What will be if javascript is disabled on my browser,It will enter wrong data.....
The Doer 3-Apr-12 2:29am    
We can use CHECK constraint also at database side.. If we can validate at client and server side,then what is the use of that CONSTRAINT in SQL SERVER???
And where this CHECK constraint is applicable??
Validating in the client side is the good practice...
 
Share this answer
 
Comments
The Doer 3-Apr-12 2:10am    
if i use CHECK constraint , then whats the advantage/disadvantage of it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900