How to use oninvalid in textarea [HTML5]

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>

Well, this is not working!

    
asked by anonymous 03.11.2015 / 21:32

1 answer

1

Expensive,

In order for the <textarea> element to be invalid it is necessary to submit the field within a <form> element, however, in its validation only the required attribute will validate the textarea. In HTML5 the pattern attribute is not available for the <textarea> element, in this case you will have to validate the length at hand.

Example to perform validation:

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

Reference

Hug.

    
03.11.2015 / 22:02