Can you require two form fields to match with HTML5?

后端 未结 7 1637
你的背包
你的背包 2020-11-29 23:56

Is there a way to require the entries in two form fields to match using HTML5? Or does this still have to be done with javascript? For example, if you have two password fiel

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 00:54

    A simple solution with minimal javascript is to use the html attribute pattern (supported by most modern browsers). This works by setting the pattern of the second field to the value of the first field.

    Unfortunately, you also need to escape the regex, for which no standard function exists.

提交回复
热议问题