我想做的是从用户那里获取一些输入(即姓名),但将字符数限制在 5 个以上....有没有办法做到这一点?
还有没有办法确保文本输入只接受数字? (尝试输入 ID)
<tr>
<th>ID:</th>
<td><input type="text" placeholder="ID" name="studet_ID"></td>
</tr>
<tr>
<th>Full name:</th>
<td><input type="text" placeholder="Full name" name="studet_name">
</td>
最佳答案
<input pattern=".{5,}" required title="5 characters minimum" type="number">
输入模式是在表单中强制输入一系列字符的最简单方法。
编辑:
- 浏览器对模式的支持有限。
- 使用数字类型作为 ID
关于php - 限制html格式的字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23768142/