简体   繁体   English

如何在 html 中获取输入字段以确保模式包含特定国家/地区代码,例如 1472,后跟 3 个数字,然后是 4 个数字

[英]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.

相关问题 我如何为我的HTML输入制作特定的模式 - How do i make a specific pattern for my html input 如何使用手机号码输入字段添加国家代码 - How to add country code with mobile number input field 如何创建带有国家代码的自定义手机号码输入框 - HTML - How to create a custom mobile number input box with country code - HTML 输入模式 - 手机号码 - 以特定数字开头 - Input pattern - Mobile number - Start with a specific numbers 如何确保自动完成适用于特定字段? - How do I ensure autocomplete works for a specific field? 仅允许特定数字的 HTML 模式输入 - HTML Pattern Input to Allow Only Specific Numbers 如何让此脚本将输入字段中输入的数字相乘? - How do I get this script to multiply a number that was typed into the input field? 如何使用正则表达式和JavaScript强制用户在输入字段中输入特定模式 - How do I force user to enter specific pattern in input field using regex and javascript 容易的。 我只想在电话号码输入字段中输入数字。 我如何在简单的js中做到这一点 - Easy one! I want only numbers to be entered in the phone number input field. How do I do that in simple js 在html输入字段中使用哪种模式来验证法语数字格式? - What pattern to use in a html input field to validate french numbers format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM