dreamkiller23 Posted May 6, 2008 Share Posted May 6, 2008 I'm working with some simple code that I can't seem to get right. In a nutshell, I'm trying to validate a password field in a form I am creating. I'd like the password field to be: at least 6 characters with the first character being a letter. at least one upper-cased letter a number, and a symbol (% or # or ~) Notice, not all the symbols. Just those 3. This is what I've come up with so far. <?php $var = "Rad#23"; //[:punct:] is just for testing purposes. $pattern = "^[a-zA-Z]+([a-zA-Z0-9]|[:punct:]){5}$"; $found = ereg($pattern, $var); if ($found==true){ echo "it's a match"; }else{ echo "no match"; } ?> The output always seems to be false i.e. no match. I'm workinf into moving this to a bigger page I've created. It looks something like: //I put [:punct:] for just testing purposes. if (!ereg("^[a-zA-Z]([a-zA-Z0-9]|[:punct:]){5}$",$e)) { echo "password must be at least 6 characters with the first character<br /> being a letter. The password should have at least one upper-cased<br /> letter, a number, and a symbol (% or # or ~)<br />"; exit(); }else{ $f = mysql_query("SELECT studentID from students where studentID=$a"); $i = mysql_num_rows($f); if($i > 0){ echo "Invalid student ID, it already exists. Try again.<br/>"; echo "<a href='http://localhost/trial/login.html'>Back to login</a>"; unset($a); exit(); } $k="INSERT into students (studentID, lastName, firstName, phoneNumber, pwd) VALUES ($a, '$b', '$c', '$d', '$e')"; mysql_query($k) or die(mysql_error()); echo "Student added!<br/>"; Any help? Please and thank you. Quote Link to comment https://forums.phpfreaks.com/topic/104361-solved-really-simple-but-difficult/ Share on other sites More sharing options...
effigy Posted May 6, 2008 Share Posted May 6, 2008 http://www.phpfreaks.com/forums/index.php/topic,194270.0.html Quote Link to comment https://forums.phpfreaks.com/topic/104361-solved-really-simple-but-difficult/#findComment-534329 Share on other sites More sharing options...
dreamkiller23 Posted May 7, 2008 Author Share Posted May 7, 2008 Thank you good sir. This is solved. Quote Link to comment https://forums.phpfreaks.com/topic/104361-solved-really-simple-but-difficult/#findComment-534855 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.