ereg() dilemma

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, new to PHP and to this group, so very sorry if this is simple or
has been covered before.  Basically want to check that a user and
password (entered in a previous page) only has characters but the
result of this is that it only ever goes to wrong!!!  please tell me
why!  I cant figure it out and feel so stupid!  I even tried with :

if(ereg("[a-z][A-Z][0-9]", $Pword) && ereg("[a-z][A-Z][0-9]", $User)) {
else {

and that also goes to the wrong.php page (which I put in a following
else), that's why I assumed try checking that it equals 1, but still no

    function redirection2() {
        header("location: ok.php");

    function redirection() {
        header("location: wrong.html");

    $User = $_POST["Username"];
    $Pword = $_POST["Password"];

    if(ereg("([a-z][A-Z][0-9])", $User, $Pword) == 1) {
    else {

Re: ereg() dilemma

"" wrote:

Quoted text here. Click to load it

You need to learn a bit more about regular expressions.

The expression "[a-z][A-Z][0-9]" matches a single lowercase letter, followed
by a single uppercase letter, followed by a single digit. Any string
containing this combination will pass your test (try "-+= xY2 &/;", for
example -- the sequence "xY2" in the middle is enough to pass your test).

In this case, something like "^[a-zA-Z0-9]+$" would probably work better,
although I don't think it's wise to restrict passwords to alphanumeric
characters only. Why not allow other symbols like /, _, !, @, #, $, %, ^, &,
* as well? And don't names sometimes contain spaces or hyphens?

You can also define minimum and maximum lengths for these strings by
replacing "+" with something like "". I'll leave you to figure out how
this all works. The documentation is perfectly clear:


phil [dot] ronan @ virgin [dot] net

Re: ereg() dilemma

Thank you thank you!  :)  fixed!  I didn't realise the [] and order
made a difference...checking out the link you provided.  i agree with
your points about spaces, underscores etc, but that unfortunately isnt
up to me in this instance but ill work out how to use them too.  ;)

thanks again :)

Re: ereg() dilemma

Quoted text here. Click to load it

I know exactly what it feels when you get help from *kind hearted*
newsgroups guys. Great expression, indeed!

I still remember my older days. Still getting a big deal help.

Raqueeb Hassan

Site Timeline