mercredi 28 janvier 2015

javascript validation prevent certain words

I am trying to prevent users from entering in certain words and special characters into a text field like "and", "or", "/","\". How do I set a variable to two or more conditions, or how better should I approach this.


To start I was trying to prevent users from entering in "and" or or into the text field.



function watchForWords(text) {
if (!text) {
return true;
}
var isValid = (text.value != "and" || text.value != "or");
if (!isValid) {
text.style.backgroundColor = "#ff8";
}
return isValid;
}

Aucun commentaire:

Enregistrer un commentaire