Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/104361-solved-really-simple-but-difficult/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.