Hacker News new | ask | show | jobs
by rhaway84773 1195 days ago
You don’t have to do all validation on the server side.

Did the user forget to fill a mandatory field? Is this phone number actually even possible? Does this zip/postal code exist? Is the age entered too low to create an account? Is the password long enough? Does it meet all the requirements. Can we dynamically show which requirements it doesn’t meet.

Even email, which you will want to verify by actually sending an email, can have some basic front end checks (is there an @ in the email entered by the user).

In fact, I bet the vast majority of validations can in fact be done in the front end in real time.

3 comments

You still have to do all the validation on the server, but you can duplicate some or all of it on the front end for convenience.

For simple projects, the validation built in to HTML form elements may be sufficient.

Client-side code is subject to potential manipulation. No validation you perform there can be a guaranteed truth for the server-side. Thus you cannot replace validation on server-side with validation on client-side.
> You don’t have to do all validation on the server side.

Yes you do.