Hey guys.... I am trying create up a test page for a small project that I am doing for a buddy of mine. What I am trying to do is this: use regular expression and have the form validation. Furthermore, I am trying to return the values on the same page. Could yall tell me what I am doing wrong here? Thanks, Adam <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test Page</title> <script type="text/javascript"> var ck_name = /^[A-Za-z0-9 ]{3,20}$/; function validate(order){ var name = order.name.value; var errors = []; if (!ck_name.test(name1)) { errors[errors.length] = "You valid Name ."; } if (errors.length > 0) { reportErrors(errors); return false; } return true; } function reportErrors(errors){ var msg = "Please Enter Valide Data...\n"; for (var i = 0; i<errors.length; i++) { var numError = i + 1; msg += "\n" + numError + ". " + errors[i]; } alert(msg); } </script> </head> <body> <form action="submit.html" enctype="multipart/form-data" id="submit1"> <table width="250" border="0" cellspacing="5"> <tr> <td>First Name:</td> <td><input name="name1" type="text" id="name1" /></td> </tr> </table> <p> <input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="Reset" id="Reset" value="Reset" /> </p> </form> </body> </html> Code (markup):
Hi, the code looks fine (at first sight), the only thing is that you never call the validation function. Based on the flow in your function validate() I believe this will help : <form action="submit.html" enctype="multipart/form-data" id="submit1" onsubmit="return validate(this)">
I been able to validate the form, but I still can't return the values and "Receipt a print" on the same page. I have this starting my form... <form action="submit.html" method="get" enctype="multipart/form-data" id="form" onsubmit="return validate(this)">
or you can use this script, Regular Expressions Taster, hxxp://www.javascriptbank.com/javascript/snippet/regular-expressions-taster/preview/ please replace xx to tt