開始我喜歡做,如果用戶輸入了不啓動22或27或06等在JavaScript中的一個數字顯示錯誤..顯示錯誤,如果現場沒有明確的數量
這裏是我的代碼..
<!DOCTYPE>
<HTML>
<form name="form" action="action.php" method="post" onsubmit="return validate()">
<span>Mobile Number(Required)</span>
<input type ="integer" name="contact" id ="contact"
value="+639" maxlength="13"/> <label id ="errorEight"></label>
<label id ="errorAlphaFour"></label>
<label id ="errorMinThree"></label><br>
</HTML>
<javascript>
function validate()
{
var valid = true;
var numeric =/^[0-9+]+$/;
if(contact.value=="")
{
document.getElementById('errorEight').innerHTML="*Field is empty";
document.getElementById('errorAlphaFour').innerHTML="";
document.getElementById('errorMinThree').innerHTML="";
valid=false;
}
else if(contact.value!="" && contact.value.match(numeric))
{
document.getElementById('errorEight').innerHTML="";
document.getElementById('errorAlphaFour').innerHTML="";
document.getElementById('errorMinThree').innerHTML="";
}
else
{
document.getElementById('errorAlphaFour').innerHTML="*Invalid number";
document.getElementById('errorEight').innerHTML="";
document.getElementById('errorMinThree').innerHTML="";
valid = false;
}
if(contact!="" && contact.value.match(numeric) && contact.value.length<13)
{
document.getElementById('errorAlphaThree').innerHTML="";
document.getElementById('errorTwo').innerHTML="";
document.getElementById('errorMinThree').innerHTML="*Minimum of 13 digits";
valid=false;
}
else
{
}
if(contact.value=="")
{
document.getElementById('errorEight').innerHTML="*Field is empty";
valid = false;
}
else
{
}
}
</javascript>
什麼我需要添加到我的代碼爲它如果用戶輸入一個數字,不與27或22或06等
'如果(value.indexOf('22' )=== 0)error' – adeneo 2015-04-03 14:31:16
此:'如果(value.match(/ ^(2 [27] | 06)/ )){/ *錯誤的東西* /}' – Amessihel 2015-04-03 14:32:29
謝謝,但它不工作.. – 2015-04-03 14:44:52