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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email Validation Question. :)

    Hi Guys/Gals

    im trying to code some error checking and all has been going well, but i have come to a pointwere is need to make sure the Email address entered is actually valid EG "abc@123.com" instead of gibberish. eg "dsfsfsfsfd"

    i have taken this from a previous Enquiry form that my boss created but i doesn't appear to work, which is intresting becuase he thought it did. so either i have deleted a little bit of it, ( which i doubt as its still the same as before) or it didnt work in the first place. if someone could please give me a little advice i would really appreicate it.

    ****************MY CODE***************
    function test(src) {
    var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    return regex.test(src);
    }
    **************************************

    Thank you in advance

    Stuart

  • #2
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Stuart:

    The problem might be the function name. test, is a javascript reserved word. You can see that it is, because you are using the test function.

    src is also a JavaScript reserved word.

    Change it to:
    Code:
    function testEmail(emailStr)
    Also, those parentheses around the second part really aren't needed:

    /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry i should of given you more info heres a bit more

    <form action="ISCpostmail.asp" method="post" name="email" id="email" onSubmit =return checkForm this)>

    *********Loads of Code i dont think is needed for this question.*********

    ******if you do need to see more code please ask ^.^ thanks alot*****

    <SCRIPT LANGUAGE="JavaScript">

    function checkForm(form) {
    var buildstr;
    var testresult

    if (form.First_Name.value =="")
    {
    alert("Please enter your first name");
    form.First_Name.focus();
    return false;
    }
    if (form.Surname.value =="")
    {
    alert("Please enter your Surname");
    form.Surname.focus();
    return false;
    }
    if (form.Address.value =="")
    {
    alert("Please enter your Address");
    form.Address.focus();
    return false;
    }
    if (form.Town.value =="")
    {
    alert("Please enter your Town");
    form.Town.focus();
    return false;
    }
    if (form.Postcode.value =="")
    {
    alert("Please enter your Postcode");
    form.Postcode.focus();
    return false;
    }

    if (form.EmailAddress.value != "")
    {
    testresult = test(form.EmailAddress.value);
    if (!testresult)
    {
    alert ("Please enter a valid EMail Address (or leave blank)");
    form.EmailAddress.focus();
    return false;
    }



    //Either telephone or Email should be provided
    if ((form.EmailAddress.value =="") && (form.Telephone.value ==""))
    {
    alert("Please enter either Telephone or Email Address");
    form.EmailAddress.focus();
    return false;
    }


    function test(src) {
    var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    return regex.test(src);
    }

    return true;
    }

    </SCRIPT>

    Thanks in advance

    Stuart

  • #4
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Stuart:

    I have a name, please address me by it.

    And PLEASE use the code tags. It's the # on the toolbar.

    Code:
    <form action="ISCpostmail.asp" method="post" name="email" id="email" onSubmit =return checkForm this)>
    Unless the above is a copy/paste error, you are missing the first paren around 'this', and the double quotes around it all:

    <form action="ISCpostmail.asp" method="post" name="email" id="email" onSubmit ="return checkForm(this)">


    You have to change this:
    Code:
    testresult = test(form.EmailAddress.value);
    to this:
    Code:
    testresult = testEmail(form.EmailAddress.value);

    and this:
    Code:
    function test(src) {
    var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    return regex.test(src);
    }
    to this:
    Code:
    function testEmail(emailStr) {
    var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    return regex.test(emailStr);
    }

  • #5
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ancora View Post
    Stuart:

    I have a name, please address me by it.

    Ancora

    im a mod on another forum (a gaming one not a coding one) and as part of the rules there we are asked to only use personal names in PMs (Unless they have used their name in the post. )

    im sorry if i coursed offense, kinda mixing rule sets in my head, it gets a bit confusing when looking at coding all day ( my brains a bit tired)

    Thank you for the advice, ( i just had our old computer guy visit us and he managed to get it to work - although he didnt use the same method as you did - i guess this means im gonna have to have a play after work and try and work out what the difference is between them)

    Once again

    Thankyou for the speedy response

    Stuart

  • #6
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Stuart:

    I think you will find that your "computer guy" did essentially the same as I. The onsubmit part of your opening form tag required the changes I made. And you cannot use "test" as a function name.

    Thank you for you explanation about "names," but I do consider it to be rude if not insulting and ungrateful when I'm not addressed by name. Machines aren't posting code here for those in need, people are. To fail or refuse to address someone by name, who expends his valuable time to help you, is to deny that person his dignity.

    It's simple common, courtesy.

    Take care.


  •  

    Posting Permissions

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