I'm looking to validate a PHP form before it gets submitted. I've seen this and it looks promising, but I need more options.
Here is the PHP code that I'm using to validate an already submitted form. I'd like to transform it to javascript so it can be validated before submission. Since I'm implementing sessions, the existing javascript back link doesn't work.
Here is the PHP code that I'm using to validate an already submitted form. I'd like to transform it to javascript so it can be validated before submission. Since I'm implementing sessions, the existing javascript back link doesn't work.
Code:
$badpassword = array("password", "123", "abc", "xyz", "qwerty", "asdf", $login, $firstname, $lastname);
for($x = 0; $x < count($badpassword); $x++) {
preg_match("/".$badpassword[$x]."/i", $pswrd, $matches);
if(count($matches) > 0) {
echo "Password contains the prohibited combination '$badpassword[$x]'.";
print ('<br />');
echo "Hit the back button to try again.";
print ('<br />');
exit ();
}
}
if( !preg_match("#[0-9]+#", $pswrd) ) {
echo "Password must include a number!";
print ('<br />');
print ('<a HREF="javascript:history.back()">Click here to try again.</a> ');
print ('<br />');
exit();
}
if( !preg_match("#[a-z]+#", $pswrd) ) {
echo "Password must include a letter!";
print ('<br />');
print ('<a HREF="javascript:history.back()">Click here to try again.</a> ');
print ('<br />');
exit();
}
if( !preg_match("#\W+#", $pswrd) ) {
echo "Password must include a symbol!";
print ('<br />');
print ('<a HREF="javascript:history.back()">Click here to try again.</a> ');
print ('<br />');
exit();
}