H5 input自定义报错

Posted by 昆山吴彦祖 on 2018.08.10

<input class="form-control num-only" type="tel" id="tel" pattern="^1[3456789]{1}[0-9]{9}$" required oninput="setCustomValidity('')" oninvalid="setCustomValidity('请输入正确格式的11位手机号');">

h5种有很多input的自带数据验证功能,非常好用。还可以通过pattern 进行复杂的数据匹配验证。 如果需要自定义数据报错,可以通过如上 方式进行。


h5