[英]how do I get an input field in html to ensure the pattern contains a specific country code eg 1472 followed by 3 number and then 4 numbers
I have different sign up pages that load for different countries, and I need the telephone input to be for that specific country, such as on one page it needs to be the country code 1234 followed by any 3 numbers and then any 4 numbers.我有针对不同国家/地区加载的不同注册页面,我需要针对该特定国家/地区输入电话,例如在一页上需要国家/地区代码 1234,然后是任意 3 个数字,然后是任意 4 个数字。 so I need the pattern for the input in the html form.所以我需要 html 表单中的输入模式。 I am dealing with it on the server side with PHP, but I want to handle it on the client side via the input restriction pattern, as to be more efficient.我在服务器端用 PHP 处理它,但我想通过输入限制模式在客户端处理它,以提高效率。 Im sure its really simple but I cant seem to find a simple solution.我确定它真的很简单,但我似乎找不到一个简单的解决方案。 thanks for your help感谢您的帮助
i tried the pattern restriction, i casn get the any 4 number, space, any 3 number, space any 4 numbers.我尝试了模式限制,我得到了任意 4 个数字,空格,任意 3 个数字,空格任意 4 个数字。 but i could not get the: '1234' specific number, space, any 3 number, space, any 4 numbers.但我无法获得:“1234”特定数字、空格、任意 3 个数字、空格、任意 4 个数字。
In this example, the pattern attribute used in the input verifies that the input follows the E.164 standard, the pattern "^+(?:[0-9]?){6,14}[0-9]$ " accepts only strings beginning with + followed by 6-14 numeric characters(optionally separated by spaces) and a numeric character at the end:在此示例中,输入中使用的模式属性验证输入是否遵循 E.164 标准,模式“^+(?:[0-9]?){6,14}[0-9]$”接受只有以 + 开头的字符串,后跟 6-14 个数字字符(可选地用空格分隔)和末尾的数字字符:
<input type="tel" id="phone" name="phone" pattern="^\+(?:[0-9] ?){6,14}[0-9]$" placeholder="+391234567890" oninput="if(this.value.length==3) this.value= this.value + ' '; this.value=this.value.replace(/^(\+39[0-9]{2})([0-9]{4})([0-9]{4})$/,'$1 $2 $3')" value="+39 " minlength="14" maxlength="14" readonly onfocus="this.removeAttribute('readonly')">
The oninput attribute used to format the phone number as the user includes it, in this case to format it as "+39 (XXX) XXXX XXXX" (Italian prefix, my country for simplicity) In addition, the value attribute is set to +39 so that the user cannot delete the international prefix. oninput 属性用于在用户输入时格式化电话号码,在本例中将其格式化为“+39 (XXX) XXXX XXXX”(意大利语前缀,为简单起见,我的国家/地区)此外,value 属性设置为 + 39 使用户无法删除国际前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.