YNWA Posted March 7, 2008 Share Posted March 7, 2008 I have my password setup in the registration form, it all works fine. However I am looking to max requirements for those who register. Things such as: Valid Email address, as you can enter anything at the minute and it will register it as your username and email address, but I want something like having the '@' as a requirement. Passwords, havin a requirement that it must be minimum characters of 5, have at least 1 number in etc... Anyone help me out? heres my form code: <script> function validate() { var email = document.getElementById("userEmail").value; if ((email == null) || (email == "")) { window.alert("Please Insert a Valid Email Address"); return false; } else { var password = document.getElementById("userPassword").value; if ((password == null) || (password == "")) { window.alert("Please Insert a Valid Password"); return false; } else { var passwordconfirm = document.getElementById("userConfirmPassword").value; if ((password) != (passwordconfirm)) { alert("Passwords do not match!"); form1.userPassword.focus(); return false; } else { var firstname = document.getElementById("userFName").value; if ((firstname == null) || (firstname == "")) { window.alert("Please Insert a Valid First Name"); return false; } else { var surname = document.getElementById("userSName").value; if ((surname == null) || (surname == "")) { window.alert("Please Insert a Valid Surname"); return false; } } } } } } </script> </head> <?php if ($_POST[op] != "yes") { echo "<h2><font face='arial' size='2' align='center'></h2> <p> Please enter your details below: </p>"; display_form(); } else { // Create a connection with the SQL server $conn = mysql_connect("localhost", "root", ""); mysql_select_db("will",$conn); $sql = "INSERT INTO registration VALUES ( '$_POST[userEmail]', '$_POST[userPassword]', '$_POST[userFName]', '$_POST[userSName]' )"; $user = $_POST[userEmail]; $checkuser = "SELECT userEmail FROM registration WHERE userEmail = '$user'"; $result = mysql_query($checkuser,$conn); // Execute the sql $record = mysql_num_rows($result); // Does record exist? if ($record != 0) { echo "<p>User Email <b> $_POST[userEmail] </b> already exists, please choose another </p>"; // If it does, tell the user display_form($_POST[userFName],$_POST[userSName],$_POST[userPassword],$_POST[userConfirmPassword]); // Ask for details again } else { if (mysql_query($sql,$conn)) // Execute the SQL { echo "User Details Added! <br />"; echo "Thank you for registering!"; } else { echo "Error, User Details Not Added, please check details and try again!<br />"; } } } function display_form($userFName="", $userSName="", $userPassword="", $userConfirmPassword="", $user="") { $display = "<form id=\"form1\" name=\"form1\" method=\"post\" onSubmit=\"return validate($_POST)\" action=\"$SERVER[php_SELF]\"> <table width=\"322\" border=\"0\"> <tr> <td width=\"147\">User Email</td> <td width=\"159\"><label> <input type=\"text\" name=\"userEmail\" id=\"userEmail\" value=\"\" /> </label></td> </tr> <tr> <td>Forename</td> <td><label> <input type=\"text\" name=\"userFName\" id=\"userFName\" value=\"$userFName\" /> </label></td> </tr> <tr> <td>Surname</td> <td><label> <input type=\"text\" name=\"userSName\" id=\"userSName\" value=\"$userSName\" /> </label></td> </tr> <tr> <td>Password</td> <td><label> <input type=\"password\" name=\"userPassword\" id=\"userPassword\" value=\"$userPassword\" /> </label></td> </tr> <tr> <td>Confirm Password </td> <td><label> <input type=\"password\" name=\"userConfirmPassword\" id=\"userConfirmPassword\" value=\"$userConfirmPassword\" /> </label></td> </tr> </table> <input type=\"hidden\" name=\"op\" value=\"yes\"> <input type=\"submit\" name=\"submit\" value=\"Submit\"> <input type=\"reset\" name=\"reset\" value=\"Reset\"> </form>"; echo $display; Cheers in advance Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 7, 2008 Share Posted March 7, 2008 You need to check into some basic regular expressions matching. Here is an email matcher that is taken from this reference site. <?php if (!preg_match('|^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i', $email)) { // Not a valid email address } ?> Quote Link to comment Share on other sites More sharing options...
YNWA Posted March 7, 2008 Author Share Posted March 7, 2008 Thanks, were in my code do I put this? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 7, 2008 Share Posted March 7, 2008 where ever it makes sense to verify that the user's email follows the valid regex pattern. Quote Link to comment Share on other sites More sharing options...
YNWA Posted March 7, 2008 Author Share Posted March 7, 2008 Seriously I aint got a clue, this PHP is too much for me. Anyone have a definate answer for me? On where to put it? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 7, 2008 Share Posted March 7, 2008 Seriously I aint got a clue, this PHP is too much for me. Anyone have a definate answer for me? On where to put it? You could take a stab at it and through it in your validation function perhabs since you want to "validate" the email, but this php stuff is just way over my head so I have no clue Quote Link to comment Share on other sites More sharing options...
YNWA Posted March 7, 2008 Author Share Posted March 7, 2008 I am putting it in validation and nothing is happening. Does anything need to be altered in my form or just the validation end? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.