How to use oninvalid in textarea [HTML5]

Asked

Viewed 361 times

0

I wanted to know how to use oninvalid in the text area.

 <textarea type="text" pattern=".{1,255}" id="mensagem" name="mensagem" class="form-control no-resize" rows="6" placeholder="A mensagem" required maxlength="255" autofocus
     oninvalid="setCustomValidity(this.validity.patternMismatch ? 'Quantidade de caracteres excedida.' : '')"></textarea>

'Cause this way it’s not working!

1 answer

1

Expensive,

So that the element <textarea> invalid it is necessary to submit the field inside an element <form>, however, in its validation only the attribute required will validate the textarea. No HTML5 the attribute Pattern is not available for the element <textarea>, in this case you will have to validate the length in hand.

Example to perform validation:

    <form>
      <textarea required oninvalid="alert('é obrigatório');"></textarea>
      <button>submit</button>
    </form>

Reference

Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.