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

PHP - Regular Expression

Options
  • 18-11-2005 5:09pm
    #1
    Registered Users 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 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 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 Posts: 410 ✭✭Drazhar


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


  • Advertisement
Advertisement