Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts

    ereg not working correct as expected

    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'] = "";} ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Try using preg_match() instead. It's usually faster, and binary safe.
    PHP Code:
    if($posts['pw1'] == '' || preg_match('/[^A-z0-9]/si'$posts['pw1']) == || $posts['pw1'] != $posts['pw2'])
    {
        echo 
    'invalid';
    }
    else
    {
        echo 
    'valid';



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •