I have a field I need to validate to allow only alphanumeric characters, which I have a funciton in place for that works fine, however I need to allow spaces as well in that field as well.
My javascript that validates my field as alphanumeric is below, I thought I could just add a space into the char list, but its not that simple. Please help.
[B]//Validate peoplesoft id
if (document.createPackage.peoplesoftId.value != “”)
{
// allow ONLY alphanumeric keys, no symbols or punctuation
var checkOK = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789”;
var checkStr = document.createPackage.peoplesoftId.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(“Please enter only letter and numeric characters in the “Alias” field.”);
document.createPackage.peoplesoftId.focus();
return (false);
}
}
else
{
alert(“Please enter a PeopleSoft ID.”);
document.createPackage.peoplesoftId.focus();
return(false);
}