Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP - Regular Expression

  • 18-11-2005 4: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,317 ✭✭✭✭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