Blue wrote:
> This JS limits the input characters into the form. How do I modify it
> so that it also allows CARRIAGE RETURN and BACKSPACE (for making text
> correction)?
> Due to the template engine I am using, I cannot use IF/ELSE statement.
> ==============================
> <form>
> <textarea name="event_description" ONKEYPRESS="if (document.layers)
> var c = event.which;
> else if (document.all)
> var c = event.keyCode;
> else
> var c = event.charCode;
> var s = String.fromCharCode(c);
> return /[0-9a-zA-Z\s,.?!@#$%&*()-]/.test(s);"></
> textarea>
> </form>
Hi,
At the moment you use a regular expression approach.
You can keep that, but first check for keyvalues CARRIAGE RETURN and
BACKSPACE, and return true if one of them.
So you'll end up with something like:
<textarea name="event_description" ONKEYPRESS="if (document.layers)
var c = event.which;
else if (document.all)
var c = event.keyCode;
else
var c = event.charCode;
var s = String.fromCharCode(c);
if (s == 13) {return true;}
if (s == 32) {return true;}
return /[0-9a-zA-Z\s,.?!@#$%&*()-]/.test(s);"></
The 13 is ENTER
The 32 is space, not BACKSPACE.
I don't remember the number of BACKSPACE. You'll have to find the number
yourself. (Or use alert(s) to test).
Regards,
Erwin Moller