[英]HTML/Java - How to restrict first 3 number of tel input field to specific number?
I try to make registration site on wordpress that also required SMS phone verification. 我尝试在wordpress上建立注册站点,这也需要SMS电话验证。 The problem is that my website is related to Pakistan.
问题是我的网站与巴基斯坦有关。 I also want to register users that are from Pakistan.
我还想注册来自巴基斯坦的用户。 But SMS gateway can send sms to world wide, so every one can register.
但是SMS网关可以将短信发送到世界各地,因此每个人都可以注册。 Now I want that when user write phone number in this field:
现在我希望当用户在此字段中输入电话号码时:
<input type="tel" name="user_phone" id="user_phone" class="input" value="" size="25">
the first three numbers must be "923". 前三个数字必须为“ 923”。 Either this pre-written in input field, user can not change/remove them or on submit user get error of "Invalid number format, number must start with 932".
在输入字段中预先写入的内容,用户无法更改/删除它们,或者在提交用户时收到“无效的数字格式,数字必须以932开头”错误。 How it possible?
怎么可能? You can check its example site at http://goo.gl/SSst3 I hope you will understand what I want to do.
您可以在http://goo.gl/SSst3上查看其示例网站,希望您能理解我想要做什么。
php can do this.. run a php script. php可以做到这一点..运行一个php脚本。 try reading my notes on php they have good examples to wat you want
尝试阅读我在php上的笔记,他们有很好的例子来帮助您
read: 读:
https://docs.google.com/file/d/0B-C0T_-acxRqamV4Y1pnUnZtenc/edit?usp=sharing https://docs.google.com/file/d/0B-C0T_-acxRqamV4Y1pnUnZtenc/edit?usp=sharing
Use javascript validation: 使用javascript验证:
On form submit have validation which checks for this: 在表单上提交验证以检查此内容:
var s = $("#phonenumber").val()
if(s.substr(0, 3)) == "923"
{
form.submit();
}
else
{
alert("Invalid number format, number must start with 932");
return false;
}
Create 2 input fields, one readonly and the other editable. 创建2个输入字段,一个为只读字段,另一个为可编辑字段。
<input type="telprefix" name="user_phone" id="user_phone_pref" class="input" value="932" size="5" tabindex="20" readonly="readonly"/>
<input type="tel" name="user_phone" id="user_phone" class="input" value="" size="20" tabindex="25" />
How does this sound : 听起来如何:
function validate(elem)
{
var anum=/(^923(\d){10}$)/; //using this regex after the number 923
// we are allowed to have 10 digits
if(anum.test(elem.value) == true)
{
elem.style.border="2px solid #0F0"; //green light
}
else
{
elem.style.border="2px solid #F00"; //red light
}
}
And in the html we have : 在html中,我们有:
<input type="text" id="phone" onchange="validate(this)" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.