0

所以我在这里有我的表格

<form name = "reservation" method = "post" action = "makereservation.php"  autocomplete="off">

(my codes here)

<input type = "submit" value = "Submit"  onclick="checkPhoneNumber(document.reservation.contact)">

</form>

我的 Javascript 函数在这里检测错误的电话号码长度

    function checkPhoneNumber(contact)
    {
        var phoneno = /^\d{10}$/;               

        if(contact.value.match(phoneno))  
        {  
            return true;  
        }  

        else  
        {  
            alert("Not a valid Phone Number");  
            return false;
        }
    }

我想问的是,当电话号码输入错误时,如何停止插入数据库?

我现在得到的是它检测到错误的电话号码长度,但它仍然插入数据库。

4

1 回答 1

1

尝试这个

<form name = "reservation" method = "post" action = "makereservation.php"  autocomplete="off"
onsubmit="return checkPhoneNumber(document.reservation.contact)">



<input type = "submit" value = "Submit" >
于 2013-09-08T18:03:50.300 回答