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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regular Expression help

    Hello all,,

    Okay I have a form with a username field. I dont want any funny characters in the username,, SO I have this REG Expression but its not working right..

    if($Uname != "[-a-zA-Z0-9._"){


    Pretty much this is suppost to say if theres anything other then a-ZA-Z or 0-9 Dont let them continue...

    but its not working.

    Any help is most apprecaited
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you're not using a regular expression function, thats why

    have a look at http://www.php.net/preg-match
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You were right!

    THanks alot ReadMe.txt!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Readme,,

    Okay this is working Half staff hehe..

    heres the code now:

    if(preg_match("/([a-zA-Z0-9])/",$Uname)){
    }else{
    //BAD STUFF IN USERNAME
    }


    okay,, this works if say the user puts in: !@#!@

    Now if they do this: AC!#@#$ it doesn't pick it up.


    So how can I get it to pick up the bad characters Period,, wether or not theres Normal characters in front of it.

    Any help is most apprecaited.
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Try something like
    Code:
    preg_match("/^[a-zA-Z0-9]/g",$Uname);

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I usualy have something like this to test usernames and pwd's
    PHP Code:
    if ((strlen($user) < 5)) {
      
    $err = (' Usernames must be at least 5 characters long.');
    }
    if (
    ereg('[^A-Za-z0-9]'$user)) {
      
    $err = (' You can use only letters and numbers.');
      if (
    ereg("['\"*_%.()]+"$user)) {
           
    $err = ('<strong>SQL-injection attack?</strong>');
      }

    Last edited by raf; 12-08-2003 at 09:52 PM.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    HEY RAF

    that works perfectly thanks!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad you got it working.

    I've set a few bug straigh from the code (i'de been cutting out my errorprocessing carelessly ... )


  •  

    Posting Permissions

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