Is there a minlength validation attribute in HTML5?

前端 未结 17 1887
日久生厌
日久生厌 2020-11-22 17:10

It seems the minlength attribute for an field doesn\'t work.

Is there any other attribute in HTML5 with the help of which I

17条回答
  •  感动是毒
    2020-11-22 17:28

    My solution for textarea using jQuery and combining HTML5 required validation to check the minimum length.

    minlength.js

    $(document).ready(function(){
      $('form textarea[minlength]').on('keyup', function(){
        e_len = $(this).val().trim().length
        e_min_len = Number($(this).attr('minlength'))
        message = e_min_len <= e_len ? '' : e_min_len + ' characters minimum'
        this.setCustomValidity(message)
      })
    })
    

    HTML

提交回复
热议问题