Is there a minlength validation attribute in HTML5?

前端 未结 17 1481
日久生厌
日久生厌 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:26

    minlength attribute is now widely supported in most of the browsers.

    
    

    But, as with other HTML5 features, IE11 is missing from this panorama. So, if you have a wide IE11 user base, consider using the pattern HTML5 attribute that is supported almost across the board in most browsers (including IE11).

    To have a nice and uniform implementation and maybe extensible or dynamic (based on the framework that generate your HTML), I would vote for the pattern attribute:

    
    

    There is still a small usability catch when using pattern. The user will see a non-intuitive (very generic) error/warning message when using pattern. See this jsfiddle or below:

    In each form type 1 character and press submit

    Input with minlength:

    Input with patern:

    For example, in Chrome (but similar in most browsers), you will get the following error messages:

    Please lengthen this text to 2 characters or more (you are currently using 1 character)
    

    by using minlength and

    Please match the format requested
    

    by using pattern.

提交回复
热议问题