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 4 of 4

Thread: preg_match help

  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    preg_match help

    Hello,

    I need a little help with preg_match / regexp, I want only a-z, A-Z (capitals) and 0-9 to be used in $str,

    What I've got so far:

    preg_match("[a-zA-Z0-9]", $str)
    This doesn't work, and I'm not exactly a regexp whiz...

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You'll probably be better off using ctype_alnum().
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Wait, unless you were trying to capture the string...I was reading another thread with RegEx and they were using it as validation...
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    $string 'test1234';

    $count preg_match('/[^A-z0-9]/'$string);
    if(!empty(
    $count))
    {
        echo 
    'invalid string';
    }
    else
    {
        echo 
    'valid string';



  •  

    Posting Permissions

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