Use 'pattern' tag in html5: <input type="text" pattern="[0-9]{6}" maxlength="6" required> 转载于:https://www.cnblogs.com/Answer1215/p/4213835.html