Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script language = "javascript">
- function validate(){
- var fname = document.forms["coursereg"]["fname"].value;
- if(fname == null || fname == ""){
- alert("Enter your name.")
- return false;
- }
- var age = parseInt(document.forms["coursereg"]["age"].value);
- if(isNaN(age)){
- alert("Enter a valid age.");
- return false;
- }
- if(age < 18 || age > 150){
- alert("Your age must be in between 18 to 150 to register.");
- return false;
- }
- var email = document.forms["coursereg"]["email"].value;
- if(email.indexOf("@")<1 || email.lastIndexOf(".")<email.indexOf("@")+2 || email.lastIndexOf(".")+2 >= email.length){
- alert("Enter a valid email address.");
- return false;
- }
- alert("Success!");
- }
- </script>
- </head>
- <body>
- <form name = "coursereg" onsubmit="return validate()" method = "post">
- <p>Name<input name = "fname" type = "text" />
- <p>Age<input name = "age" type = "text" />
- <p>Email<input name = "email" type = "text" />
- <p><input name = "submit" type = "submit">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement