SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    valid email check, form wont sumbit if valid

    hi, im using the email validation on this page..

    http://www.web-wise-wizard.com/javas...l-address.html

    however, when the email is valid, it just returns to the form. i want it to proceed with the form submit when it is valid..

    below is the my form and the script.

    thanks

    form
    Code:
    <form action="TESTsend.asp" method="post" onsubmit="return(linkCheckValidation(testAddress))">
    <p><input name="myplace" id="myplace" type="hidden" value="<%=placeNAME%>" /></p>
    <p><input name="salprice" id="salprice" type="hidden" value="<%=Trim(rs("salPRICE"))%>" /></p>
    <p><input name="newsalprice" id="newsalprice" type="hidden" value="<%=trim(newsalPRICE)%>" /></p>
    <p><input name="estprice" id="estprice" type="hidden" value="<%=Trim(rs("estPRICE"))%>" /></p>
    <p><input name="newestprice" id="newestprice" type="hidden" value="<%=trim(newestPRICE)%>" /></p>
    <p><input name="mpvprice" id="mpvprice" type="hidden" value="<%=Trim(rs("mpvPRICE"))%>" /></p>
    <p><input name="newmpvprice" id="newmpvprice" type="hidden" value="<%=trim(newmpvPRICE)%>" /></p>
    <p><input name="exeprice" id="exeprice" type="hidden" value="<%=Trim(rs("exePRICE"))%>" /></p>
    <p><input name="newexeprice" id="newexeprice" type="hidden" value="<%=trim(newexePRICE)%>" /></p>
    <p><input name="nstprice" id="nstprice" type="hidden" value="<%=Trim(rs("nstPRICE"))%>" /></p>
    <p><input name="newnstprice" id="newnstprice" type="hidden" value="<%=trim(newnstPRICE)%>" /></p>
    <p><input name="placeid" id="placeid" type="hidden" value="<%=rs("placeID")%>" /></p><br />
    	
    	<p class="mainpage"><b>EMAIL QUOTES</b><br /><br />You can send these quotes via email. Just enter an email address and hit Send.</p><p><input style="margin-left:20px;width:200px;" type="text" class="txtbox" id="testAddress" name="testAddress" /></p>
    <p><input style="margin-left:20px;background-color:#666666;font-weight:bold;font-size:12px;font-family:arial;color:white;width:80px;height:27px;" value="Send >>" id="confirm" name="confirm" type="submit" /></p>
    
    </form>



    jscript
    Code:
    function checkValidation ( addressField ) {
        if ( stringEmpty ( addressField.value ) )
            alert ( "Error! There is no E-Mail address entered" );
        else if ( noAtSign ( addressField.value ) )
            alert ( "Error! The E-Mail address does not contain an '@' character" );
        else if ( nothingBeforeAt ( addressField.value ) )
            alert ( "Error! An E-Mail address must contain at least one character before the '@' character" );
        else if ( noLeftBracket ( addressField.value ) )
            alert ( "Error! The E-Mail address contains a right square bracket ']',\nbut no corresponding left square bracket '['" );
        else if ( noRightBracket ( addressField.value ) )
            alert ( "Error! The E-Mail address contains a left square bracket '[',\nbut no corresponding right square bracket ']'" );
        else if ( noValidPeriod ( addressField.value ) )
            alert ( "Error! An E-Mail address must contain a period ('.') character" );
        else if ( noValidSuffix ( addressField.value ) )
            alert ( "Error! An E-Mail address must contain a two or three character suffix" );
        else
            return (true);
    
        return ( false );
    }
    
    function linkCheckValidation ( formField ) {
        if ( checkValidation ( formField ) == true ) {
            alert ( 'E-Mail Address Validates OK' );
        }
    
        return ( false );
    }
    
    function stringEmpty ( address ) {
        // CHECK THAT THE STRING IS NOT EMPTY
        if ( address.length < 1 ) {
            return ( true );
        } else {
            return ( false );
        }
    }
    
    function noAtSign ( address ) {
        // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
        if ( address.indexOf ( '@', 0 ) == -1 ) {
            return ( true )
        } else {
            return ( false );
        }
    }
    
    function nothingBeforeAt ( address ) {
        // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
        if ( address.indexOf ( '@', 0 ) < 1 ) {
            return ( true )
        } else {
            return ( false );
        }
    }
    
    function noLeftBracket ( address ) {
        // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
        if ( address.indexOf ( '[', 0 ) == -1 && address.charAt ( address.length - 1 ) == ']' ) {
            return ( true )
        } else {
            return ( false );
        }
    }
    
    function noRightBracket ( address ) {
        // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
        if ( address.indexOf ( '[', 0 ) > -1 && address.charAt ( address.length - 1 ) != ']' ) {
            return ( true );
        } else {
            return ( false );
        }
    }
    
    function noValidPeriod ( address ) {
        // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
        if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
            return ( false );
    
        // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
        if ( address.indexOf ( '.', 0 ) == -1 )
            return ( true );
    
        return ( false );
    }
    
    function noValidSuffix ( address ) {
        // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
        if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
            return ( false );
    
        // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
        var len = address.length;
        var pos = address.lastIndexOf ( '.', len - 1 ) + 1;
        if ( ( len - pos ) < 2 || ( len - pos ) > 3 ) {
            return ( true );
        } else {
            return ( false );
        }
    }

  2. #2
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to return false only when e-mail is not valid, but you are returning false always. So change to:
    Code javascript:
    function linkCheckValidation ( formField ) {
        if ( checkValidation( formField ) == true ) {
            //alert ( 'E-Mail Address Validates OK' );
            return true;
        }
        return false;
    }

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that has done the trick

    thank you very much for the speedy response

  4. #4
    secure webapps for all Aleksejs's Avatar
    Join Date
    Apr 2008
    Location
    Riga, Latvia
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are welcome!
    Also, if your function linkCheckValidation does not do anything more than you have written, then you can just write:
    <form action="TESTsend.asp" method="post" onsubmit="return(checkValidation(testAddress))">
    and remove function linkCheckValidation altogether.


Bookmarks

Posting Permissions

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