Javascript odd validation question

Associate
Joined
4 Mar 2007
Posts
315
Location
United Kingdom
I usually stick to Ajax for validation, however my question would be; if I were to have, let say. twenty or so inputs on a screen and I wanted to validate ALL these inputs, including radio buttons, drop downs etc.

What would be the best way of doing so?

Is there a kind of foreach loop I can run for example?

I know I can validate in PHP and send the user back, but this is, well kind of pointless.

Regards,
 
jQuery AND php. If you worry about those people that turn javascript off. Though that's a VERY small amount of people.
 
There's no harm in validating both ends. Typically you'd develop the validation at the server side first to see what validation you actually need, then replicate the functionality on the client side.
 
I have just created a class based jquery validation plugin allowing you to validate against pretty much anything you want.

As mentioned, you really should be validating on both server and client side, server being a requirement.

I am tweaking and polishing the plugin at the moment but I am more than happy to share the code if you want to take a look.

You point it at the form and it will check the classes of the elements and validate accordingly.
 
I use the jQuery Validation Plugin which works very well; it's actually very easy to use and takes a couple of minutes generally to set-up. You can also validate locally or via AJAX.

Also: validate both at the PHP side and the client side as everyone has has suggested.. never trust user input, they could easily have JavaScript disabled and be passing rubbish data.
 
Back
Top Bottom