ereg() dilemma

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rachellara1979@gmail.com

    ereg() dilemma

    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)) {
    redirection2();
    }
    else {
    redirection();
    }

    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
    good. HELP ME PLEASE!!

    <?php
    function redirection2() {
    header("locatio n: ok.php");
    }

    function redirection() {
    header("locatio n: wrong.html");
    }

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

    if(ereg("([a-z][A-Z][0-9])", $User, $Pword) == 1) {
    redirection2();
    }
    else {
    redirection();
    }
    ?>

  • Philip Ronan

    #2
    Re: ereg() dilemma

    "rachellara1979 @gmail.com" wrote:
    [color=blue]
    > ... 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)) {
    > redirection2();
    > }
    > else {
    > redirection();
    > }[/color]

    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 "{4,20}". I'll leave you to figure out how
    this all works. The documentation is perfectly clear:

    <http://php.net/manual/en/reference.pcre. pattern.syntax. php>

    --
    phil [dot] ronan @ virgin [dot] net



    Comment

    • Goog79

      #3
      Re: ereg() dilemma

      Thank you thank you! :) fixed! I didn't realise the [] and order
      made a difference...ch ecking 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 :)

      Comment

      • Raqueeb Hassan

        #4
        Re: ereg() dilemma

        > Thank you thank you! :) fixed!

        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
        Bangladesh

        Comment

        Working...