I try to make registration site on wordpress that also required SMS phone verification. 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. 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". 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". How it possible? You can check its example site at http://goo.gl/SSst3 I hope you will understand what I want to do.
php can do this.. run a php script. try reading my notes on php they have good examples to wat you want
read:
https://docs.google.com/file/d/0B-C0T_-acxRqamV4Y1pnUnZtenc/edit?usp=sharing
Use javascript validation:
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.
<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 :
<input type="text" id="phone" onchange="validate(this)" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.