views:

544

answers:

8

Hi,

It has been long time since we have been validating our forms using javascript. I am sure this must be the case with most other developers.

Question:

What if the user (or probably a bad guy) disables javascript?

You are lost !!

Is javascript validation worth of it?
Should we ever use it now?
Are there any solutions to this?

Correct me if I am wrong.

Thanks

+36  A: 

Is javascript validation worth of it?

Yes, as it provides better user experience and preserves bandwidth

Should we ever use it now?

Yes for the aforementioned reasons

Are there any solutions to this?

Yes: Use server side validation as well

Darin Dimitrov
server side as well? much work then y not go with server side only?
Sarfraz
See point 1 of Darin's answer.
Pekka
That's the reason that f.e. the validation part of the .NET framework creates both javascript and server-side validation code when adding validators.
Jan Jongboom
+1: You **must** validate fully on the server anyway, but JS validation makes things *much* nicer for the users. Your comment, Sarfraz, is a bit like saying "We need to provide a command-line interface for scripting? Why bother building a GUI on top of it?"
Andrzej Doyle
+1, js validation is just for convenience, the server-side validation is indispensable!! This is usually the bigger security-hole of newbies projects!
DaNieL
+2  A: 

Using java script is not wrong. We've been using it since a long time. It is used for applying client side validations.

Still we should implement server side validations so that a BAD GUY would not be able to break the application.

Ritz
+4  A: 

What if the user (or probably a bad guy) disables javascript?

As said before: Simply do not rely on the client. Never do so. Check everything on the server again.

Should we ever use it now?

Yes - so the user immediately sees what's wrong. Otherwise he had to post back the data first which may take a while. By the way you reduce traffic to your server.

It's simply more inuitive.

//EDIT: BTW: The ASP.NET ValidationRules contain both client-side and server validation as far as I know.

winSharp93
+2  A: 

Client-side (Javascript) validation is about usability, nothing else. If the cost of implementing is not worth the perceived increase in usability, then don't spend the time on it. These days it's pretty easy to do though!

I don't think you can do without server-side validation, however, since this is the only thing that provides you with any security.

Rob Fonseca-Ensor
+1  A: 

If you're looking to save time, go with server-side only. If you want better performance and user experience, add client-side validation afterward. Never rely on client-side validation, for the reasons you state. All critical validation should occur on the server ... even if duplicated on the client.

Jess
+2  A: 

Javascript validation is good because it provides a better user experience.

You should however never rely on it and should validate on the server regardless.

cletus
A: 

In a multi-tiered / service orientated environment validation should exist on multiple levels to allow for better reuse while still maintaining a secure application. Validation on the client side, whether in a desktop app, or web site/application should be there for a better user experience to prevent postbacks to the server everytime for validation, hence costing more bandwidth and user time. If client-side validation cannot be moved entirely to the front end then consider using ajax for a partial postback to a server side validation routine, while retaining a better customer experience but allowing a programmer to maintain the validation rules centrally.

Second to the client side, but more importantly, server side code should validate the data before persisting it via a data layer or passing it to another server side method/service, to employ business rules around the data and help prevent errors in data integrity. Lastly, the persistence layer itself (the immediate interface to the database or other storage mechanism) should validate the data being stored, again to prevent errors in data integrity and possibly further business rules. The last thing you want is a data store with useless data.

Employing this method will keep you data secure and integrity in line. On reuse of either you persistence layer, your data layer or your front-end presentation thereafter, in your own site (or via a web service, desktop application or mobile app), if designed properly, these validation routines are already in place and can be re-employed. This should prove to be of great benefit to you alone, and your colleagues and your management, if you happen work in a team.

nealkernohan
A: 

javascripts are useful for client side validation. But you cannor rely only on them. You must use server side validation against the posted data. Javascript just prevents unnecessary posts to the server.

Ozan BAYRAM