conan318 Posted June 24, 2011 Share Posted June 24, 2011 hi i just making a simple form and trying to get the email to validate with no luck can someone tell me what im doing wrong thanks <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Billy's gift baskets</title> <link href="main.css" rel="stylesheet" type="text/css"> <script type="text/javascript"> <!-- if (document.images) { pic1= new Image(); pic1.src="logo.png"; pic2= new Image(); pic2.src="logo2.png"; } </script> <SCRIPT language="JavaScript"> function check() { if (n.value==""){ alert('please enter your name') } if(c.value==''){ alert('please enter your credit card number') } if(cv.value==''){ alert('please enter your cvc number') } if (e.value==""){ alert(' We need your email details') } function validateForm() { var x=document.forms["form1"]["e"].value var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } else { window.confirm('Press ok to Comfirm purchase') window.location="index.html"; }}} </script> </head> <body> <div class="banner"> <img src="logo.png" name="pic1" border="0" id"pic1" onmouseover="document.pic1.src='logo2.png'" onmouseout="document.pic1.src='logo.png'"> </div> <form name="form1"> <table> <tr> <td>Name</td> <td><input type="text" size"20" name="n" id="n" maxlength="20" value=""/></td> </tr> <tr> <td> Credit card</td> <td><input type="text" name="c" id="c" size"20" maxlength="20"/></td> </tr> <tr> <td> CVC</td> <td><input type"text" name="cv" id="cv" size"3" maxlength="3" /></td> </tr> <tr> <td>email</td> <td><input type"text" size "30" name="e" id="e" maxlength="30" /></td> </tr> <tr> <td>Feedback</td> <td><input type="text" size"50" maxlength="50" /></td> </tr> <tr> <td>Submit</td> <td><input type="button" Value="Submit" onclick="check()"></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/240283-email-vaildaiton/ Share on other sites More sharing options...
Adam Posted June 24, 2011 Share Posted June 24, 2011 You're not defining the variables n, c, cv, or e anywhere. Instead of giving them an ID each and using getElementById to return the element object though, use the DOM tree to access them. You can even use a with structure to prevent much modification to your code: with (document.form1) { if (n.value=="") { alert('please enter your name') } // ... } On a side-note you're calling the function "check()" only when the user clicks the submit button. How many times do you press Enter on the last field, or tab to the button and press Enter, to submit? Instead of assigning it to the click event of the button, assign it to the submit event of the form. That will call the function no matter how they submit the form. Quote Link to comment https://forums.phpfreaks.com/topic/240283-email-vaildaiton/#findComment-1234207 Share on other sites More sharing options...
EdwinPaul Posted June 24, 2011 Share Posted June 24, 2011 Read the article on http://isemail.info/about for an example on how to check for valid email-address. Quote Link to comment https://forums.phpfreaks.com/topic/240283-email-vaildaiton/#findComment-1234364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.