Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need just a little more help with email verification - almost there!

    Hi there, I've worked this code 100 different ways and had help from the forums, but I still can't get my javascript to verify that two emails are typed in identically.
    I've bolded the section of the code that isn't working to make it easier. Thank you for all your help!

    <SCRIPT LANGUAGE="JavaScript">
    <!--


    var error = new createerror();
    var errors = new Array();
    errors[31] = "Illegal character in a numeric input";
    errors[64] = "The field is empty.";
    errors[131] = "Illegal character. You can only enter letters and blank spaces.";
    errors[150] = "Please input a valid email address.";
    errors[151] = "Please input a valid ten digit number.";
    errors[152] = "The email addresses are not the same.";

    var alphachars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var emailFilter=/^.+@.+\..{2,3,4,6}$/;
    var digits = "0123456789";




    function createerror() {
    this.val = 0;
    return this;
    }
    function validateForm() {
    var correct;
    correct = checkblank(document.myForm.name.value, error);
    if (!correct) {
    alert('Name: ' + errors[error.val]);
    document.myForm.name.focus();
    return false;
    }
    correct = checkalpha(document.myForm.name.value, error);
    if (!correct){
    alert('Name: ' + errors[error.val]);
    document.myForm.name.focus();
    return false;
    }

    correct = checkblank(document.myForm.lastname.value, error);
    if (!correct) {
    alert('Last Name: ' + errors[error.val]);
    document.myForm.lastname.focus();
    return false;
    }
    correct = checkalpha(document.myForm.lastname.value, error);
    if (!correct){
    alert('Last Name: ' + errors[error.val]);
    document.myForm.lastname.focus();
    return false;
    }




    correct = checkblank(document.myForm.email.value, error);
    if (!correct) {
    alert('Email: ' + errors[error.val]);
    document.myForm.email.focus();
    return false;
    }
    correct = checkemail(document.myForm.email.value, error);
    if (!correct) {
    alert('Email: ' + errors[error.val]);
    document.myForm.email.focus();
    return false;
    }





    correct = checkblank(document.myForm.confirmemail.value, error);
    if (!correct) {
    alert('Confirm Email: ' + errors[error.val]);
    document.myForm.confirmemail.focus();
    return false;
    }
    correct = checkemail(document.myForm.confirmemail.value, error);
    if (!correct) {
    alert('Confirm Email: ' + errors[error.val]);
    document.myForm.confirmemail.focus();
    return false;
    }

    correct = checkblank(document.myForm.phone.value, error);
    if (!correct) {
    alert('Phone: ' + errors[error.val]);
    document.myForm.phone.focus();
    return false;
    }
    correct = checkphonenumber(document.myForm.phone.value, error);
    if (!correct) {
    alert('Phone: ' + errors[error.val]);
    document.myForm.phone.focus();
    return false;
    }


    return true;
    }

    function checkblank(fieldValue,error)
    {
    if (fieldValue.length == 0) {
    error.val = 64;
    return false;
    }
    for (var i = 0; i<fieldValue.length; i++) {
    if (fieldValue.charAt(i) != ' ' && fieldValue.charAt(i) != '\t') {
    return true;
    }
    }
    error.val = 64;
    return false;
    }
    function isalpha(sChar){return (alphachars.indexOf(sChar) >= 0)}

    function checkalpha(fieldValue,error)
    {
    for (var i = 0; i<fieldValue.length;i++)
    {
    if (!isalpha(fieldValue.charAt(i))){
    error.val = 131;
    return false;
    }
    }
    return true;
    }


    function checkemail(){
    var str=document.myForm.email.value
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    testresults=true
    else{
    error.val = 150;
    return false;
    }
    return true;
    }



    function checkconfirmemail(){
    var str=document.myForm.confirmemail.value
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    testresults=true
    else{
    error.val = 150;
    return false;
    }
    return true;
    }




    function checkemailmatch(error) {
    var str = document.myForm.email.value;
    var str2 = document.myForm.confirmemail.value;
    if (str == str2) {
    testresults = true;
    }
    else {
    error.val = 152;
    return false;
    }
    }



    function checkphonenumber(str){
    var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
    if (re.test(str))
    testresults=true
    else{
    error.val = 151;
    return false;
    }
    return true;

    }

    // -->
    </SCRIPT>

    </HEAD>

    <BODY>
    <H2>Contact Us</H2>
    <h4>*Indicates a required field</h4>
    <FORM NAME="myForm" METHOD="post"
    ACTION="http://free.allforms.mailjol.net/u/d0ac0bdf.php">
    *Name:<BR>
    <INPUT TYPE="text" size="30" NAME="name" ><br>
    *Last Name:<BR>
    <input type="text" size="30" name="lastname"><br/>
    Street Address:<br />
    <input name="Street" type="text" size="30" />
    <br/>
    Unit#:<br/> <input name="Unit" type="text" size="5" />
    <br />
    City:<br /> <input name="City" type="text" size="30" />
    <br/>
    Postal Code: <br /><input name="PostalCode" type="text" size="7"/>
    <br/>
    *Email address:<BR>
    <INPUT TYPE="text" size="30" NAME="email"><br>
    *Confirm Email address:<BR>
    <INPUT TYPE="text" size="30" NAME="confirmemail"><br>
    *Phone number:<BR>
    <INPUT TYPE="text" size="30" NAME="phone"><br>
    Mobile number:<BR>
    <INPUT TYPE="text" size="30" NAME="mobile"><br />
    Work Phone:<br/>
    <input name="Work" type="text" size="20" maxlength="12" /><br />
    Comments: <br/>
    <textarea name="Comments" rows="10" cols="50">Let us know what you think!</textarea>
    <br />


    <INPUT TYPE="submit" VALUE="Submit Data" onClick="javascript:return validateForm();">
    <INPUT TYPE="reset" VALUE="Reset Form">
    </FORM>


    </BODY>
    </HTML>

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's not working because it's not returning a value if the strings match.

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I think what you're saying is I need a "return true;" in there, so I put it in but it's still not working
    ~Vanessa


    function checkemailmatch(error) {
    var str = document.myForm.email.value;
    var str2 = document.myForm.confirmemail.value;
    if (str == str2) {
    testresults = true;
    }
    else {
    error.val = 152;
    return false;
    }
    return true;
    }

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Where's your checkemailmatch function call in the validation function?

  • Users who have thanked tomws for this post:

    Vanbot (06-13-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •