Good Am! i just would like to ask from the experts what is the best html FORM validation practice that i can do with my application.
is it advisable that i validate my forms on JavaScripts or i have to create classess for them?
Printable View
Good Am! i just would like to ask from the experts what is the best html FORM validation practice that i can do with my application.
is it advisable that i validate my forms on JavaScripts or i have to create classess for them?
The jave script will be executed at client side without going to server for validation and it is faster which saves the user time. So with javascript you can have fast validation and users can correct immediately. If you have lot of fields and complex validation and if your javascript code increases there will be delay in form loading and response.
If you have a validation with database tables then you must connect to database so at that time your validation can be java classes. The java classes validation will be executed at server side fastly and user form code will be reduced. If you have very complex validation of files also then only you should go for classes.
So based on your requirement you can have javascript at client side prefarable.
Never assume that client side validations will work even if you have them.
Always have server side validations. Client side validations are just to give users quick feedback.
@r035198x sir you mean that i should not use java scripts as my validation and rather use java classes to be safe? or you can have your java scripts then if not work it will be catched by the javal class validations? how can i do this?
If it is form validation only, why not java script? even validation framework in struts uses javascript. But javascript provides you only form client side validation which is manily to check the users' input. For something like username cannot be less than 6 characters, there is no need to send data to the server and validate. It is just waste of time. Server side validation is usually done for authentication purposes. Both validations are important but if it is only form validation, why not JavaScript?
ic so can i expect that javascript validation will work on every client that will be using it? what about sir r035198x reply that js will not work all the time for every client
Read my reply again and don't confuse Javascripts with Java scripts. Java runs on the server. Javascript runs on the client browser.
You must always have server side validations.
You can have client side validations too to make the users' lives easier.
Javascript can be turned off by users on their browsers meaning that your validations don't run. This will result in a very unfortunate situation for your data. Your data may also be manipulated through other clients (that are not browsers) and you can't guarantee that everyone who writes a client to use your data will always validate correctly.
Always have server side validations.
Ok now its clear to me! thank you verymuch :D