Validating form fields with ajax
You want to react to more than just a submit event, like keyup and blur.
You may need different ways to specify validation rules according to the server-side enviroment you are using on different projects.
You can only do that if you know what it should be, and in that case you don't need to bother with the form.= -1) alert("only numbers please") strip all non numeric values: var val = yourfield.value.replace(/\D/g,""); - Ensure that the contents of a text field is shorter than a certain length if (!yourfield.value.length removing all of the following characters: ",.- " var val = yourfield.value.replace(/[,.\- ]/g,"") // mask the minus as otherwise it will define a range Checkout any Regular Expression reference of your choice to learn more on this.Usually you'll just want to check if Modern Web Design Using Java Script & DOMJava Script is back! This is the best book on the subject I’ve ever read, showing you step-by-step the smartest ways to create usable, useful DHTML effects to enhance your site.
When you have a name attribute like user[name], make sure to put the name in quotes. Another common problem occurs with this code: triggers another round of validation, resulting in another call to submit Handler, and voila, recursion.