Validating all fields on a form

The following Javascript can be used to verify that a value has been entered in all fields on a form.

function validate(form) {
    var regex = /\w+/;
    for(var i = 0; i < form.length; i++) {
        var curr_el = form.elements[i];
        if(!regex.test(curr_el.value)) {
            alert("Please fill out all fields.");
            curr_el.focus();
            return false;
        }
    }
    return true;			
}
This entry was posted in JavaScript. Bookmark the permalink.

Comments are closed.