Email Validate function (small error)

Thread Solved

Join Date: Mar 2008
Posts: 63
Reputation: sukhy_1 is an unknown quantity at this point 
Solved Threads: 3
sukhy_1 sukhy_1 is offline Offline
Junior Poster in Training

Email Validate function (small error)

 
0
  #1
Mar 28th, 2008
Hello the code below checks if the email is real but when a real email is entered for some reason or another it states undefined when the sumit button is clicked even though the email entered is real. if no email is entered is says enter a an email, if a wrong email is entered it states no a vaild email. thats the only error but cant figure why its doing that any ideas guys

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Comment Form</TITLE>
  4. <Script language = javascript>
  5.  
  6. function Validate() {
  7. Message = ""
  8.  
  9. Message = Message + CheckEmail()
  10.  
  11.  
  12. if (Message == "") {
  13. return true
  14. }
  15. else {
  16. alert(Message)
  17. return false
  18. }
  19.  
  20. }
  21.  
  22.  
  23. function CheckEmail() {
  24. email = document.f1.Email.value
  25. AtPos = email.indexOf("@")
  26. StopPos = email.lastIndexOf(".")
  27. Message = ""
  28.  
  29. if (email == "") {
  30. Message = "Not a valid Email address" + "\n"
  31. return Message
  32. }
  33.  
  34. if (AtPos == -1 || StopPos == -1) {
  35. Message = "Not a valid email address" + "\n"
  36. return Message
  37. }
  38.  
  39. if (StopPos < AtPos) {
  40. Message = "Not a valid email address" + "\n"
  41. return Message
  42. }
  43.  
  44. if (StopPos - AtPos == 1) {
  45. Message = "Not a valid email address" + "\n"
  46. return Message
  47. }
  48.  
  49.  
  50. }
  51.  
  52.  
  53.  
  54. </script>
  55. </HEAD>
  56. <BODY BGCOLOR = White>
  57. <form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain>
  58.  
  59. <tr>
  60. <td height="40" valign="top" colspan="4" align="center"><b>Email:
  61. <input type="text" name="Email" size="30">
  62. </b></td>
  63. </tr>
  64.  
  65. <tr align="center">
  66. <td height="80" colspan="2" valign="top">&nbsp;</td>
  67. <td valign="top" colspan="3">
  68. <input type="submit" name="Submit" value="Submit This Form">
  69. <input type="reset" name="Submit2" value="Reset This Form">
  70. </td>
  71. </tr>
  72. <tr>
  73. <td height="0"></td>
  74. <td width="40"></td>
  75. <td></td>
  76. <td></td>
  77. <td></td>
  78. </tr>
  79. <tr>
  80. <td height="1"></td>
  81. <td></td>
  82. <td width="10"></td>
  83. <td></td>
  84. <td></td>
  85. </tr>
  86. </table>
  87. </form>
  88. </BODY>
  89. </HTML>
Last edited by peter_budo; Mar 30th, 2008 at 5:51 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: Email Validate function (small error)

 
0
  #2
Mar 28th, 2008
Your answer


  1. <HTML>
  2. <HEAD>
  3. <TITLE>Comment Form</TITLE>
  4. <Script language = javascript>
  5.  
  6. function Validate() {
  7. var Message = ""
  8.  
  9. Message = Message + CheckEmail()
  10.  
  11.  
  12.  
  13. if (Message == ""){
  14. return true
  15. }
  16. else {
  17. alert(Message)
  18. return false
  19. }
  20.  
  21. }
  22.  
  23.  
  24. function CheckEmail() {
  25. email = document.f1.Email.value
  26. AtPos = email.indexOf("@")
  27. StopPos = email.lastIndexOf(".")
  28. Message = ""
  29.  
  30. if (email == "") {
  31. Message = "Not a valid Email address" + "\n"
  32. return Message
  33. }
  34.  
  35. if (AtPos == -1 || StopPos == -1) {
  36. Message = "Not a valid email address" + "\n"
  37. return Message
  38. }
  39.  
  40. if (StopPos < AtPos) {
  41. Message = "Not a valid email address" + "\n"
  42. return Message
  43. }
  44.  
  45. if (StopPos - AtPos == 1) {
  46. Message = "Not a valid email address" + "\n"
  47. return Message
  48. }
  49.  
  50. return Message
  51. }
  52.  
  53.  
  54.  
  55. </script>
  56. </HEAD>
  57. <BODY BGCOLOR = red>
  58. <form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain>
  59. <table width="709">
  60. <tr><td height="40" valign="top" colspan="4" align="center"><b>Email:<input type="text" name="Email" size="30"></b></td><td height="80" colspan="2" valign="top"><input type="submit" name="Submit" value="Submit This Form"></td>
  61. <td valign="top" colspan="3"><input type="reset" name="Submit2" value="Reset This Form"></td></tr>
  62.  
  63. </table>
  64. </form>
  65. </BODY>
  66. </HTML>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 550 | Replies: 1
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC