The javascript form validation works fine , but for the first name and the last name field, it is accepting numeric values , but I want it to accept only alphabets. Could you please let me know whats wrong in the code below. Also is there any other error in the below code.

--javascript file:-

// JavaScript Documentvar strErrors = "";

function validateForm() { // clean out the string of errors if validation fails more than once strErrors = "";

function validateEmailAddress() { // get the value of what was erntered into the email field var strEmail = document.getElementById("emailAdd").value;

var emailRegex = /^[\\w\\.]+@[a-zA-Z_]+?\\.[a-zA-Z\\.]{2,6}$/;
// check the validity of the email address now then cos something has been entered
// into the email field - already checked by the checkIfFieldEmpty() function
if (!emailRegex.test(strEmail)) {
strErrors += "Please enter a valid email address.~";
}

}

function validatePhone() { // get the value of what was erntered into the nrobame field var strName = document.getElementById("phoneNo"); var stripped = strName.value.replace(/[\(\)\.\-\ ]/g, '');

Anything inside the square brackets preceded by ^ means not this. So if it matches anything other than a-z then true. The (g) means globally i.e. through out the string and the (i) mean case insensitive.

Also see that you are basically repeating the same function twice for first and last name. Would be good to make that just one name checking funtion.

By the way, arjun98854, if you are interested in learning JavaScript, SitePoint's book Simply JavaScript has a short section dedicated to form validation. It would help you to write your own code that is honestly cleaner and more flexible than what you have now.