Form Input Validation With Javascript

June 05, 2009

Input validation with javascript is an essential part of any large day to day website. Its major advantage is that it can be processed client side thus avoiding avoidable load on the server.
If your running a PHP based website which is struggling to cope with load and your using basic php form validation. You could switch your form validation to Javascript.

You should treat your javascript validation as your first line of defence, as javascript source can be read by a user its easy enough to work around it if you know what your doing. So you will still need to keep your second line of defence ie your PHP code to do the second lot of checking.

However the javascript will help to limit load for people who genuinely make honest mistakes.

Heres a example of form validation.

Firstly lets make our Form


Whats your name:   

About me

Hello! I'm David Heward, how are you going? I'm a Senior Devops/Build Engineer, specialising in AWS & Cloud Automation. Based in London. Strong 10+ year background in Software development. Have a read of my blog. Have a look at some of my working projects. Contact me at @davehewy or on Linkedin.