Forum Moderators: open
function validateLastname(fld) {
//alert("inside");var error = "";
var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\'\[\]]/;
if (fld.value == "") {
error = "You didn't enter a Last Name.\n";
document.getElementById("flname").innerText = "Enter Last Name";
}else if (illegalChars.test(fld.value)) {
error = "Last Name contains illegal characters.\n";
document.getElementById("flname").innerText = "Contains Illegal Characters";} else {
document.getElementById("flname").innerText = "";
}
return error;
}
My question is should I be adding additional characters like ^ and & or anything else that would leave us open to attack?
Thanks!
Mat
[edited by: tedster at 12:53 am (utc) on Feb. 6, 2008]
[edit reason] fix formatting [/edit]
You must enforce the restrictions server-side (PHP, ASP, etc.), with the JS just used as a simple check before the form is submitted.