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

  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Preg_match

    I can not figure out how to preg_match to allow for only
    1.character from A-Z regardless of case
    2.And to allow for numeric characters as well
    3.Not allow whitespace or any other characters


    if (preg_match ('[^0-9]',$input))
    {
    }
    else{

    Any help much appreciated.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    your description needs to be more clear, it's a bit ambiguous.
    PHP Code:
    //a single letter or number
    $pattern='#^[a-z0-9]$#i';

    //1 or more (letters or numbers)
    $pattern='#[a-z0-9]+#i';

    //a single letter followed by 1 or more numbers
    $pattern='#[a-z][0-9]+#i'
    the 'i' in each case tells it to be case-insensitive.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Gjay for your response.

    Your code is great, but its still not taking into consideration any whitespace.

    So basicaly it allows user to put space between characters.

    hmm preg_match seems to b a programming language on its own *jokes.

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,769
    Thanks
    19
    Thanked 155 Times in 146 Posts
    PHP Code:
     if (preg_match ('/^([a-zA-Z0-9]+)$/',$input) == && preg_match('/\s+/',$input) == 0)
    {

    }
    else
    {


    preg_match returns "1" if a match is found, "0" if no match is found....
    Last edited by chump2877; 12-01-2006 at 10:13 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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