我想为电话号码创建一个输入字段。我正在使用 JavaScript 动态创建输入字段。
<input type="text" id="phone" name="phone">
如何限制用户只能输入 10 位数字以获得电话号码。
最佳答案
试试这个
<input type="text" name="country_code" title="Error Message" pattern="[1-9]{1}[0-9]{9}">
这将确保
- 是数字
- 最多 10 个字符
- 第一位不为零
关于javascript - 如何限制用户在输入元素中输入 10 位数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445408/