// returns true if the form was valid; false otherwise.
function validateForm() {
var allLetters = /^[a-zA-Z]+$/;
var letter = /[a-zA-Z]/;
var number = /[0-9]/;
var email = document.order_form.user_email.value;
var password = document.order_form.password.value;
var invalid = [];
if (!allLetters.test(firstName)) {
invalid.push("*First Name");
}
if (!allLetters.test(surname)) {
invalid.push("*Surname Name");
}
if (email.indexOf("@") < 1 || email.lastIndexOf(".") < email.indexOf("@") + 2 || email.lastIndexOf(".") + 2 >= email.length) {
invalid.push("*Email");
}
if (password.length < 4 || !letter.test(password) || !number.test(password)) {
invalid.push("*Password");
}
if (invalid.length != 0) {
alert("Please provide response: \n" + invalid.join("\n"));
return false;
}
return true;
}
I hope this will help.
Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners :