Hi,
I'm using an example of some validation i found on the internet but it does not allow me to submit Spaces between words.
E.g
i can submit "this_is_a_test" but can not insert "This is a test"
CODE:
<!--
function validateFormOnSubmit(theForm) {
var reason = "";
reason += validateUsername(theForm.comments);
reason += validateEmpty(theForm.comments);
if (reason != "") {
alert("Some fields need correction:\n" + reason);
return false;
}
return true;
}
function validateEmpty(fld) {
var error = "";
if (fld.value.length == 0) {
fld.style.background = 'Yellow';
error = "The required field has not been filled in.\n"
} else {
fld.style.background = 'White';
}
return error;
}
function validateUsername(fld) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter a username.\n";
} else if (illegalChars.test(fld.value)) {
fld.style.background = 'Yellow';
error = "The username contains illegal characters.\n";
} else {
fld.style.background = 'White';
}
return error;
}
//-->
Does anyone know how i can insert spaces between words?
Sorry about this, i'm not very good with JS.
Thanks in advance
I'm using an example of some validation i found on the internet but it does not allow me to submit Spaces between words.
E.g
i can submit "this_is_a_test" but can not insert "This is a test"
CODE:
<!--
function validateFormOnSubmit(theForm) {
var reason = "";
reason += validateUsername(theForm.comments);
reason += validateEmpty(theForm.comments);
if (reason != "") {
alert("Some fields need correction:\n" + reason);
return false;
}
return true;
}
function validateEmpty(fld) {
var error = "";
if (fld.value.length == 0) {
fld.style.background = 'Yellow';
error = "The required field has not been filled in.\n"
} else {
fld.style.background = 'White';
}
return error;
}
function validateUsername(fld) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter a username.\n";
} else if (illegalChars.test(fld.value)) {
fld.style.background = 'Yellow';
error = "The username contains illegal characters.\n";
} else {
fld.style.background = 'White';
}
return error;
}
//-->
Does anyone know how i can insert spaces between words?
Sorry about this, i'm not very good with JS.
Thanks in advance