Hi, I am trying to combine the two pieces of code below for a form validation script, but am having some difficulty. Check the form field is not empty: Check the field contains no special characters: At the top of the file, I am using: I want to both check the field is not empty, and also prevent special characters being inserted for security, but am not able to figure out how to combine the two. If anyone would be sop kind as to help me, I would be most appreciative. Thanks
function validateMessage(fld) { var error = ""; if (fld.value.length == 0) { fld.style.background = 'Yellow'; error = "The Message has not been filled in.\n" } else { var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; for (var i = 0; i < fld.value.length; i++) { if (iChars.indexOf(fld.value.charAt(i)) != -1) { error = "Your username has special characters. \nThese are not allowed.\n Please remove them and try again."; break; } } } if (error == "") { fld.style.background = 'White'; } return error; } Code (markup):