Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP - Regular Expression

  • 18-11-2005 05:09PM
    #1
    Registered Users, Registered Users 2 Posts: 410 ✭✭


    I am using preg-match to check and see if a name entered is any combination of letters, numbers, hyphens and underscores

    [PHP]preg_match("/[a-zA-Z0-9\-\_]+/", $name)[/PHP]

    where am i going wrong?


Comments

  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    What's the error you're getting?


  • Registered Users, Registered Users 2 Posts: 410 ✭✭Drazhar


    no error, it just doesnt work

    i use it in an if statement. so if name is hello9_9, it will enter the if statement, but if it was hello9_* (or any other character not a letter, number, - or _) then it goes to the else bit


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Could you post all the code please. I'll have a look.


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    i use it in an if statement. so if name is hello9_9, it will enter the if statement, but if it was hello9_* (or any other character not a letter, number, - or _) then it goes to the else bit
    Is this what it should do, or what it does do right now?

    I'm guessing that you want to make sure the input only contains these characters, in which case just change your regular expression to
    "/^[a-zA-Z0-9\-\_]+$/"


  • Registered Users, Registered Users 2 Posts: 410 ✭✭Drazhar


    Seamus, your the man dawg, have a virtual pint on me!!:D
    pint.jpg


  • Advertisement
Advertisement