1

I have this text area / form:

<div><textarea name="subject" rows="3" cols="60" placeholder="Please Enter Your Subject..." required="true"></textarea></div>

And obviously if the user types into the text area: su/bject Then su\bject is shown.

Is there a HTML way to make sure no '\' or any other characters apart from Aa - Zz are taken from the form?

Thanks in advance

1 Answer 1

1

When submitting, you can catch the result without any unwanted chars by doing this:

yourTextArea.value = yourTextArea.value.replace( /[^a-zA-Z]/g , '');

Or if you want to strip them right on key press, then modify your text area like this:

<textarea onkeyup="this.value = this.value.replace( /[^a-zA-Z]/g, '');" name="subject" rows="3" cols="60" placeholder="Please Enter Your Subject..." required="true"></textarea>
3
  • The last one nearly works 100%..But if I have the / at the end, i.e subject/ then the slash is still added
    – Thomas
    Mar 28, 2015 at 14:55
  • I have edited the second one but am still getting the same problem. I am a bit confused with the first one, where exactly would I place that in my code and how would it look?
    – Thomas
    Mar 28, 2015 at 15:02
  • @Thomas edited the second one; the first one is just general example.
    – nicael
    Mar 28, 2015 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.