Help will be appreciated! I want to a form validation script that will check a the following things of the user name value.
1. if no value is entered, client will get alert msg like ” Enter any user name”
2. If any charecter other than ”abcdefghijklmnopqrstuvwxyz0123456789-_” is enterted, client will get alert msg like “Use only characters and numbers in your user name!”
3. if length of the value is <2 and >20 is enter entered, client will get alert msg like ”Enter any user name from 2 to 20 charecters long”
4. if some certains words for example, Admin, Administrator, Operator, Manager are entered, client will get alert msg like ”You entered a restricted name. Use something else”.
I currently have this script:
function validate(field) {
var valid = “abcdefghijklmnopqrstuvwxyz0123456789-_”
var ok = “yes”;
var temp;
for (var i=0; i<field.value.length; i++) {
temp = “” + field.value.substring(i, i+1);
if (valid.indexOf(temp) == “-1”) ok = “no”;
}
if (ok == “no”) {
alert(“Use only characters and numbers in your user name!”);
field.focus();
field.select();
}
}
Can anyone help me making a script combining all those features?