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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    105
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Exclamation Allow all preg-match

    Hello people !

    I was wondering if someone could help me, letting this code to allow all preg match. I think i have writed the preg-match wrong, i will allow all this symbols in my loginscript: - . : # & @ _ $

    And this is the code:
    Code:
            else if (!preg_match('#^([0-9a-z@:.\-_;,!])*$#i', $subuser))  {

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    I recomend using varibles in this situation, my friend. Put all the things you want allowed in a variable and then put the variable into the preg_match function.

    In this case:
    PHP Code:
    $pattern '/- . : #  & @ _ $/';
    $subuser ' '
    else if (!
    preg_match($pattern$subuser))  {
    /// code
     

    As I always say, I could be wrong.. Feel free to correct me anyone.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • Users who have thanked Chris Hick for this post:

    Haidar (06-02-2011)

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Posts
    105
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Chris Hick View Post
    I recomend using varibles in this situation, my friend. Put all the things you want allowed in a variable and then put the variable into the preg_match function.

    In this case:
    PHP Code:
    $pattern '/- . : #  & @ _ $/';
    $subuser ' '
    else if (!
    preg_match($pattern$subuser))  {
    /// code
     

    As I always say, I could be wrong.. Feel free to correct me anyone.
    Alright seems very good! But please could you write it for me instead in the same way as my line? Because i'm not so god in php and im using a bit for diffucult script, when i change to your lines i got error message. So maybe the best way is just modify the line i put? i would be very happy if you could help me!

  • #4
    Regular Coder
    Join Date
    Jan 2010
    Posts
    105
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I still need help :/

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    What exactly are you trying to do? Are you trying to make sure the username is within a certain limit and will only allow those character mentioned above?
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #6
    Regular Coder
    Join Date
    Jan 2010
    Posts
    105
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Chris Hick View Post
    What exactly are you trying to do? Are you trying to make sure the username is within a certain limit and will only allow those character mentioned above?
    Yupp exactly! But the code is kind of wired, so i have to write them in the same line.

  • #7
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    I have no clue why I didn't tell you this until now, it completely slipped my mind. You are better off using preg_match(); to search for things that you do not want in the username or something specific in the username that must be included. The preg_match function looks for the first match of what you tell it to look for then pops out 0 being false and 1 being true. So, you would be better off looking for what you don't want it to include rather than something you want it to allow.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #8
    New Coder
    Join Date
    Sep 2010
    Location
    The Twilight Zone
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    I don't think your regex is correct since it won't match any letters or numbers. I may be wrong. This should work:

    /^[- . : # & @ _ $a-zA-Z0-9]{1,}$/

    It matches 1 or more of all the characters within the class, including letters and numbers.
    Last edited by Ahlahn; 06-03-2011 at 07:06 PM.


  •  

    Posting Permissions

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