[英]Restraining mobile number input
I have a form where I am accepting mobile number from users. 我有一个接受用户手机号码的表格。 Condition is that, I have to accept only the numbers starting from either 7, 8, or 9 and max length should be ten.
条件是,我必须只接受从7、8或9开始的数字,并且最大长度应为10。 I am using the following code for the same :
我使用相同的以下代码:
<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}/">
But still the both the conditions are failing : 但是,这两个条件仍然都失败了:
1) starting from 7, 8, or 9 & 2) max length should be 10. 1)从7、8或9&2开始)最大长度应为10。
Please guide me. 请指导我。 Thanks in anticipation.
谢谢您的期待。
The pattern attribute works with the following input types: text, date, search, url, tel, email, and password
. pattern属性适用于以下输入类型:
text, date, search, url, tel, email, and password
。
Your input type is number
so the pattern is ignored. 您的输入类型是
number
因此该模式将被忽略。
Change your input type to text
or tel
and it will work as expected. 将输入类型更改为
text
或tel
,它将按预期工作。
Source: https://www.w3schools.com/tags/att_input_pattern.asp 资料来源: https : //www.w3schools.com/tags/att_input_pattern.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.