SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post need help in mail validation using js function


    look if u tried to write abc.abc@yahoo it works correctly
    but i need it to be abcabc@yahoo.com
    so the dot in the first one is before @
    but i need it to be after
    i want to detect if the dot is before @ neglectit and continue bcoz the dot must be after the @


    here it's my code in (funtionc.js)
    function fd()
    {
    do {

    //mail

    var y;
    y=document.getElementById('emal').value
    if((y.length==0) || (y.charAt(0)==' '))
    {
    alert(mailerror);
    document.getElementById('email').style.color="#FF0100";
    document.getElementById('emal').focus();
    return false;
    break;
    }
    var p
    p=document.getElementById('emal').value;
    if((p.length!=0))
    {
    document.getElementById('email').style.color="#8B8B8B";
    }
    if (document.getElementById('emal').value.indexOf('@',0)==-1 ||
    document.getElementById('emal').value.indexOf('@',0)== 0 ||
    document.getElementById('emal').value.indexOf('.',0)==-1 ||
    document.getElementById('emal').value.indexOf('.',0)== 0)
    {
    alert(invalidmail);
    document.getElementById('email').style.color="#FF0100";
    document.getElementById('emal').focus();
    return false;
    break;
    }



    }while(0)
    }





    and this is mypage.php


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript" language="JavaScript1.2" src="library/stmenu.js"></script>
    <script src="library/prototype.js" type="text/javascript"></script>
    <script src="library/scriptaculous.js" type="text/javascript"></script>
    <script type="text/javascript" src="library/functions.js"></script>





    <script language="javascript">
    {

    var mailerror='Please enter your E-mail';
    var invalidmail='Please enter a correct e-mail address';

    }
    </script>




    </head>


    <body>

    <table width="80%" border="0" cellpadding="0" cellspacing="0" class="res" >
    <form id="form3" name="form3" method="post" action="index.php" onSubmit="return fd();">


    <tr>
    <td width="25%" align="left" valign="middle" >
    <label for="emal" id="email"> E-Mail * </label></td>
    <td width="5%" align="center" valign="middle" >/td>
    <td width="55%" height="25" align="left" valign="middle" ><input name="emal" type="text" id="emal" size="44" /></td>
    </tr>



    <tr>
    <td align="left" valign="middle" >&nbsp;</td>
    <td align="center" valign="middle" >&nbsp;</td>
    <td align="center" valign="middle">

    <div align="center">
    <input name="15" type="submit" class="submit" id="15" value="Submit" />
    <input type="hidden" name="subm" id="subm">
    </div></td>
    </tr>
    </form>
    </table>

    </body>
    </html>




    i tried to put the code u sent to me inside my form validation but it did not work
    could you plz help me
    thnx in advance

  2. #2
    SitePoint Enthusiast Chris Webb's Avatar
    Join Date
    Oct 2008
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to learn regular expressions my friend!

    Try this for size:

    function checkEmail(inputvalue){
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){
    alert("true");
    }else{
    alert("false");
    }
    }
    Chris Webb | twitter/tgnwg
    Visit TheGoodNamesWereGone.com for
    free Javascript goodness, help with your Website and more


  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx alot but i'm a beginner in web developing and i dont know where to put it in my code
    sorry again but i dont know how to fix my problem
    thhnx for ur help

  4. #4
    SitePoint Enthusiast Chris Webb's Avatar
    Join Date
    Oct 2008
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, replace your entire unction fd() function with this (hopefully it will work):

    function fd(inputvalue){
    var inputvalue =document.getElementById('emal').value;
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){
    return true;
    }else{
    return false;
    }
    }
    Chris Webb | twitter/tgnwg
    Visit TheGoodNamesWereGone.com for
    free Javascript goodness, help with your Website and more


  5. #5
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    really thnx for your help
    but i cant show my alert (" invalid mail entry ");
    or
    ("correct mail");
    to be sure that it works correctly

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Then make a slight modification to the already provided script.

    Code javascript:
    function fd(inputvalue){
        var inputvalue = document.getElementById('emal').value;
        var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        if (pattern.test(inputvalue)) {
            alert("correct mail");
            return true;
        } else {
            alert("invalid mail entry");
            return false;
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •