...

View Full Version : form validation + illegal characters script help



Matt_Helvey
06-09-2004, 06:51 PM
Hi, how is it possible to make a function that allow only letter (both upper- n' lowercase) and "." (dot) and "-". In other words, how do i define characters that will pass a form validation (to be inputted into a textfield). In this validation script ->


function guestbooksubmit(form) {
missinginfo = "";
if (document.guestbook.from_name.value == "") {
missinginfo += "\n Name";

}
else return true;
}


so how can i put that fuction (only letters, . , -) into this??
(note: that this is not the whole script)

homerUK
06-10-2004, 01:25 AM
you probably want to try regexp... I am not great on it, so this might help you http://www.devguru.com/Technologies/ecmascript/quickref/regexp.html or someone will hopefully post some code for you here...

basically you wanna compare the string to values in the regexp.. if they dont match, then throw an error.. if they do, then submit the form....

sorry couldnt be more help at the mo!

liorean
06-10-2004, 01:51 AM
function guestbooksubmit(form) {
missinginfo = "";
if (!/^[a-z. -]+$/gi.test(document.guestbook.from_name.value)){
missinginfo += "\n Name";
}
else
return true;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum