Leon Posted October 24, 2015 Share Posted October 24, 2015 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="en-us" http-equiv="Content-Language" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Untitled 1</title> </head> <body> <form name="checkmail" onSubmit="return checkemail()" method="post" action="javascript:alert('The form is submitted!!!')"> Please enter your email<br /> <input name="Text1" type="text" /> <input name="Button1" type="submit" value="submit" /> </form> <script language="javascript" > function checkemail(){ var email=document.checkmail.Text1.value; if (email.indexOf(' ')==-1 && 0 < email.indexOf('@') && email.indexOf('@')+5< email.length )return true; else alert('Invalid Email address') return false; } </script> </body> </html> if (email.indexOf(' ')==-1 && 0 < email.indexOf('@') && email.indexOf('@')+5< email.length )return true; else alert('Invalid Email address') return false; } Can someone tell me what does this part of code do? i have look through w3cschool and i dont understand. Link to comment Share on other sites More sharing options...
Ash! Posted October 24, 2015 Share Posted October 24, 2015 (edited) Hi, Looks like it checks whether the text entered is a valid email address or not. If you are confused by the indexOf part, check this: http://www.w3schools.com/jsref/jsref_indexof.asp Edited October 24, 2015 by Ash! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now