0

検証フォームを作成しようとしています。検証フォームを正しく機能させることができません。電話機能が機能していません。ユーザーが[送信]を押しても、フォームを送信しただけなのかわかりません。誰か助けてもらえますか?

html:

<form onsubmit="return validate();" name="formValidation">
    <label>First Name:</label>
    <input type="text" name="firstName" /><br /><br />
    <label>Last Name:</label>
    <input type="text" name="lastName" /><br /><br />
    <label>E_mail:</label>
    <input type="text" name="Email" onchange="validateEmail(this.value)"/><br /><br />
    <label>Confirm E_mail:</label>
    <input type="text" name="confirmEmail" onchange="validateEmail(this.value)"/><br /><br />
    <label>Address:</label>
    <input type="text" name="Address" /><br /><br />
    <label>Telephone nr:</label>
    <input type="text" name="fld" /><br /><br />
    <br />
    <p>submit your form: </p><input type="submit" value="Submit" />
</form>

js:

function validate(){
    if(document.formValidation.firstName.value == "" ||
    document.formValidation.lastName.value == "" ||
    document.formValidation.Email.value == "" ||
    document.formValidation.confirmEmail.value == "" ||
    document.formValidation.Address.value == "" ||
    document.formValidation.fld.value == "")
    {
        alert("Please fill all the boxes before submitting!");
        return false;
    } else if (telPhone(document.formValidation.fld.value)!=""){
        alert(error)
        return false
    }else {

        alert('Your form has been submitted!');
    }

}
function validateEmail(Email)   
{  
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Email))  
  {  
    return true;  
  }  
    alert("You have entered an invalid email address!")  
    return (false) 
}

function telPhone(fld) {
    var error = "";
   if (fld == "") {
        error = "You didn't enter a phone number.";
    } else if (isNaN(fld)) {
        error = "The phone number contains illegal characters.";
    } else if (fld.length != 10) {
        error = "The phone number is the wrong length. Make sure you included an area code."
    }

    return error;
}
4

1 に答える 1

0
<form onsubmit="return validate();" name="formValidation"  action="fileto redirect here" method="post">
于 2012-11-30T12:21:10.640 に答える