...

View Full Version : ereg not working correct as expected



jasonc310771
12-29-2007, 12:42 PM
i only want to allow A to Z and a to z and 0 to 9

basically numbers and letter and case sensitive.

this is what i have but it shows the error even though both fields are the same and contain something.

is there somethingwrong with the ereg ?

<?
if($posts['pw1'] == "" || $posts['pw1'] != ereg("^[a-zA-Z0-9]+$", $posts['pw1'] ) || $posts['pw1'] != $posts['pw2']) { ?>The passwords you have entered are not the same, or contains invalid characters.<br>
<? $submit = "notok"; $posts['pw1'] = ""; $posts['pw2'] = "";} ?>

Inigoesdr
12-29-2007, 01:02 PM
Try using preg_match() (http://php.net/preg_match) instead. It's usually faster, and binary safe.

if($posts['pw1'] == '' || preg_match('/[^A-z0-9]/si', $posts['pw1']) == 1 || $posts['pw1'] != $posts['pw2'])
{
echo 'invalid';
}
else
{
echo 'valid';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum