| | |
Email Validate function (small error)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 63
Reputation:
Solved Threads: 3
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
php Syntax (Toggle Plain Text)
<HTML> <HEAD> <TITLE>Comment Form</TITLE> <Script language = javascript> function Validate() { Message = "" Message = Message + CheckEmail() if (Message == "") { return true } else { alert(Message) return false } } function CheckEmail() { email = document.f1.Email.value AtPos = email.indexOf("@") StopPos = email.lastIndexOf(".") Message = "" if (email == "") { Message = "Not a valid Email address" + "\n" return Message } if (AtPos == -1 || StopPos == -1) { Message = "Not a valid email address" + "\n" return Message } if (StopPos < AtPos) { Message = "Not a valid email address" + "\n" return Message } if (StopPos - AtPos == 1) { Message = "Not a valid email address" + "\n" return Message } } </script> </HEAD> <BODY BGCOLOR = White> <form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain> <tr> <td height="40" valign="top" colspan="4" align="center"><b>Email: <input type="text" name="Email" size="30"> </b></td> </tr> <tr align="center"> <td height="80" colspan="2" valign="top"> </td> <td valign="top" colspan="3"> <input type="submit" name="Submit" value="Submit This Form"> <input type="reset" name="Submit2" value="Reset This Form"> </td> </tr> <tr> <td height="0"></td> <td width="40"></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="1"></td> <td></td> <td width="10"></td> <td></td> <td></td> </tr> </table> </form> </BODY> </HTML>
Last edited by peter_budo; Mar 30th, 2008 at 5:51 am. Reason: Keep It Organized - please use [code] tags
Your answer
PHP Syntax (Toggle Plain Text)
<HTML> <HEAD> <TITLE>Comment Form</TITLE> <Script language = javascript> function Validate() { var Message = "" Message = Message + CheckEmail() if (Message == ""){ return true } else { alert(Message) return false } } function CheckEmail() { email = document.f1.Email.value AtPos = email.indexOf("@") StopPos = email.lastIndexOf(".") Message = "" if (email == "") { Message = "Not a valid Email address" + "\n" return Message } if (AtPos == -1 || StopPos == -1) { Message = "Not a valid email address" + "\n" return Message } if (StopPos < AtPos) { Message = "Not a valid email address" + "\n" return Message } if (StopPos - AtPos == 1) { Message = "Not a valid email address" + "\n" return Message } return Message } </script> </HEAD> <BODY BGCOLOR = red> <form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain> <table width="709"> <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> <td valign="top" colspan="3"><input type="reset" name="Submit2" value="Reset This Form"></td></tr> </table> </form> </BODY> </HTML>
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Poulate a option field on change
- Next Thread: another question about securing and passing variables
Views: 550 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date directory display download dynamic echo email error file files folder form format forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





