I am trying to validate a text box. Only certain characters are allowed in the text box (The code is below). However this code will not allow the user to enter a white space between words:
My House
My Home
I have tried numerous variations (below) but I can't stand it anymore. It's driving me crazy.
[^A-Za-z0-9\s]
[^A-Za-z0-9/\s]
[^A-Za-z0-9/\s*]
What am I missing? Can anybody help.
function validChara(formField,fieldLabel){
var result = true;
var charas = formField.value.search("[^A-Za-z0-9]");
if(formField.value.length > 0 && charas >= 0) {
alert('Please do not use Special Characters in your ' + fieldLabel +'');
formField.focus();
result = false;
}
return result;
}
My House
My Home
I have tried numerous variations (below) but I can't stand it anymore. It's driving me crazy.
[^A-Za-z0-9\s]
[^A-Za-z0-9/\s]
[^A-Za-z0-9/\s*]
What am I missing? Can anybody help.
function validChara(formField,fieldLabel){
var result = true;
var charas = formField.value.search("[^A-Za-z0-9]");
if(formField.value.length > 0 && charas >= 0) {
alert('Please do not use Special Characters in your ' + fieldLabel +'');
formField.focus();
result = false;
}
return result;
}