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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help validating forms

    Hey,

    I really, really need some help with form validation. I have tried over 20 codes to get an email address to validate but none of them work. I'm not very good with Javascript! As far as I can see I am placing the function in the correct place and also calling it at the right time. I would be greatful for any help any one could give me.

    Thanks

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How can we possibly help you when you have failed to provide any codes and/or the email validation requirements.....

    .....Willy

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You may try this very very simple email validator:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    validate(f){
    var 
    p=0;
    var 
    = new Array()
    v=f.email.value.split('');
    for (var 
    i=0;i<v.length;i++){
    if((
    v[i]=='@')||(v[i]=='.')){
    p++
    }
    }
    if(
    p<2){
    alert('Please type a valide e-mail');
    f.email.focus();
    return 
    false
    }
    }
    </script>
    </head>
    <body>
    <form onsubmit="return validate(this)">
    e-mail <input name="email" type="text">
    <br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html> 
    Well, it is not a complete validator (the email validator is a really complex problem), but it covers all the possibilities but only according to the following presumtions:

    1. the minimum mail string type is something like 'name@domain.extension' (it have at least one "@" and one "." characters)
    2. the most common user's mistakes are
    - omitting the input
    - omitting the extension (that means the dot)
    - omitting the @
    3. users are well intentioned people and their omitions are accidentally ones, by pure mistake
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, was a bit tired been at it for over 10 hours. Told you I was not very good at it. Its a shopping cart so the form is for customers to order their good. So they submit all their details like name, address, credit card details, email and at the end their is a submit button to submit the order. The order is submitting fine but I can't get anything to validate like poscode, credit card details and email address. I would like a pop up alert telling them if anything is incorrect. I have just tried the code but it does not work.

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function validate(f){
    var p=0;
    var v = new Array()
    v=f.email.value.split('');
    for (var i=0;i<v.length;i++){
    if((v[i]=='@')||(v[i]=='.')){
    p++
    }
    }
    if(p<2){
    alert('Please type a valide e-mail');
    f.email.focus();
    return false
    }
    }
    </script>
    </head>
    <body>
    <form onsubmit="return validate(this)">
    e-mail <input name="email" type="text">
    <br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

  • #5
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for this but I'm afraid it did not work for me.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Thanks for this but I'm afraid it did not work for me.
    I beg your pardon??? It should work on every browsers I know. At least it works for what I have now installed (NS6, NS7, Mozilla 1.7, Firefox, Opera 5) on XP on PC ...

    It validates the classic way. If there is no email or if the string has not a '@' and a '.', an alert message apperas and the submit is stopped. If not, the data is submitted.

    What in fact don't work for you???
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm using netscape 7. There was no alert telling me the email address was not valid when I entered just letters.

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Should work either. check whether you have javascript enable or not,

    Edit-Preferences-Advanced-Scripts&Plugins

    and make sure to check the small checkbox Enable javaScript for "Navigator"
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Both of these are checked but there is still no alert message advising that an invalid email address has been entered.

  • #10
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    it must work when you press the submit button. Isn't that what you wanted?

    If you don't see the alert, there must be something wrong with your browser or your OS..

    Can you see the alert on this?
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </
    head>
    <
    body onload="alert('see this?')">
    </
    body>
    </
    html
    By the way, make sure your code has the doctype and the content-type.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #11
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I want the alert when you press the submit button. I can see the see this one you gave me but still nothing with the first piece of code. I have this in at the top
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <link rel=stylesheet type="text/css" href="JLstyle.css">
    <BODY>
    <IMG SRC="crakinlogo.gif" width=100% height=150><BR>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    function validate(f){
    var p=0;
    var v = new Array()
    v=f.email.value.split('');
    for (var i=0;i<v.length;i++){
    if((v[i]=='@')||(v[i]=='.')){
    p++
    }
    }
    if(p<2){
    alert('Please type a valide e-mail');
    f.email.focus();
    return false
    }
    }

    Then in my form I have this
    <TD><B class="first">Email Address:</B></TD>
    <TD><INPUT TYPE="EMAIL" NAME="email" SIZE=30 onsubmit="return validate(this)"></TD>

  • #12
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    TD><B class="first">Email Address:</B></TD>
    <TD><INPUT TYPE="EMAIL" NAME="email" SIZE=30 onsubmit="return validate(this)"></TD>
    onsumit event handler is to be used only on [b]FORM[/] tag. not on on input. I have gave you an example which you have modified, thatis why you got no proper answer. Review my example, please.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #13
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry but I don't know what you mean. This is my first time doing Javascript and I don't really understand it. Do you mean that my form can't be in a table if I want to validate it?

  • #14
    Regular Coder
    Join Date
    Jul 2004
    Location
    mile high city
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The table is not the problem. You are referencing the validation function from the wrong point in your html - on the input tag within the form rather than form tag itself.

    Your opening form tag should look like something like this...

    Code:
    <form onsubmit="return validate(this)"...
    Applying onsubmit to a single input has no effect because you are actually submitting the form which then collects all the data from your inputs.

  • #15
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you mean somewhere here <FORM NAME="form1" METHOD="POST" ?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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