限制手机号码输入

时间:2017-09-02 08:08:18

标签: html mobile input restrictions

我有一个表格,我接受用户的手机号码。条件是,我必须只接受从7,8或9开始的数字,最大长度应为10。我使用以下代码:

<input name="wno" id="wno" type="number" placeholder="Whats App No." required="required" minlength="10" maxlength="10" style="border-color:black" pattern = "/(7|8|9)\d{9}/">

但两种条件仍然失败:

1)从7,8或9开始 2)最大长度应为10。

请指导我。谢谢你的期待。

1 个答案:

答案 0 :(得分:0)

pattern属性适用于以下输入类型:text, date, search, url, tel, email, and password

您的输入类型为number,因此会忽略该模式。

将您的输入类型更改为texttel,它将按预期工作。

来源:https://www.w3schools.com/tags/att_input_pattern.asp