电话号码没有得到验证的JavaScript

我正在做的形式和我的验证功能的工作原理,但完全忽略的电话号码,并允许它被发送。电话号码没有得到验证的JavaScript

我需要发生的是,如果电话号码犯规正好包含10个号码就被拒绝。

如果我复制确切的代码,并把它放在一个单独的功能:

<button onclick="CheckTelephone()">Click</button> 

function CheckTelephone(){

var Telephone = document.forms["OrderForm"]["Telefoon"] .value.length;

if (Telefoon != 10){

document.getElementById("Error").innerHTML = "Telefoon nummer moet 10 cijfers bevatten.";

setTimeout("ErrorClear()",5000);

return false;}

}

但是当我提交了完整的代码我的形式,它允许发送任意数量的:(一路底部)

<form onsubmit="return validate()" name="OrderForm"> 

<input type="submit" id="SubmitForm" name="SubmitForm" value="Plaats Bestelling">

// Form validation

function validate(){

// Variables

var TotalAmount = document.getElementById('TotalAmount').innerHTML;

var Voornaam = document.forms["OrderForm"]["Voornaam"] .value;

var Achternaam = document.forms["OrderForm"]["Achternaam"] .value;

var Tussenvoegsel = document.forms["OrderForm"]["Tussenvoegsel"] .value;

var Email = document.forms["OrderForm"]["Email"] .value;

var EmailCheck = document.forms["OrderForm"]["EmailCheck"] .value;

var Telefoon = document.forms["OrderForm"]["Telefoon"] .value.length;

var PositionAt = document.forms["OrderForm"]["Email"] .value.indexOf('@');

var PositionDot = document.forms["OrderForm"]["Email"] .value.indexOf('.');

var NotNumbers = /^[0-9]$/;

// Checks filled out or not (|| = OR(= Of))

if (TotalAmount == 0 || TotalAmount <= 0){

document.getElementById("Error").innerHTML = "U heeft geen hoeveelheid oliebollen gekozen.";

setTimeout("ErrorClear()",5000);

return false;}

if ( Voornaam == null || Voornaam == ""

|| Achternaam == null || Achternaam == ""

|| Email == null || Email == ""

|| EmailCheck == null || EmailCheck == ""

|| Telefoon == null || Telefoon == ""){

document.getElementById("Error").innerHTML = "Niet alle verplichte velden zijn ingevuld.";

setTimeout("ErrorClear()",5000);

return false;}

// Checks if email adresses are the same or contains . and @

if (PositionAt <1 || PositionDot-PositionAt <2){

document.getElementById("Error").innerHTML = "Het E-Mail adres bevat geen @ of . tekens.";

setTimeout("ErrorClear()",5000);

return false;}

if (EmailCheck == Email){return true;}else{

document.getElementById("Error").innerHTML = "De ingevoerde E-Mail adressen zijn niet gelijk.";

setTimeout("ErrorClear()",5000);

return false;}

// Checks if Telephone number contains 10 digits

if (Telefoon != 10){

document.getElementById("Error").innerHTML = "Telefoon nummer moet 10 cijfers bevatten.";

setTimeout("ErrorClear()",5000);

return false;}

// Somehow lets the phone number go trough even tough it's the exact same code

// If all correct

return true;

}

如果有人能告诉我这是为什么发生或我在做什么错那将是极大的赞赏

回答:

你的函数调用,

onclick="CheckTelefoon()" .... 

和你的函数定义,

function CheckTelephone(){ .... 

使两者特有的无差错运行代码。

以上是 电话号码没有得到验证的JavaScript 的全部内容, 来源链接: utcz.com/qa/267398.html

回到顶部