SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Regex Help

  1. #1
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex Help

    Can I have some help with regex. I'm using mod_rewrite for a social networking site, and I want to make sure every user name can be accounted for. Here is my current code.

    Code:
    ^/([A-Za-z]+,[0-9]+)$ /user.php?id=$1
    That will cover any username in the format "AbCaBc123", but I also want it to include periods, underscores, letters, and numbers anywhere in the user name. Can someone show some code that will do that?

    Also, how can I restrict my registration form/MySQL database to only allow #'s, letters, and "." or "_"?

    Thanks for the help!

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace
    ([A-Za-z]+,[0-9]+)
    with
    ([^/]+)

    As for the second part of your question, you will need to post your registration code here, because it is very different.s
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    SitePoint Enthusiast BMorganVA's Avatar
    Join Date
    Mar 2010
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the user name part of my registration code.

    PHP Code:
    $resultUser mysql_query(
        
    sprintf(
            
    "SELECT Username FROM sq_users WHERE Username = '%s'",
            
    mysql_real_escape_string($_POST['user'])
        )
    );
    if(
    !== mysql_num_rows($resultUser)){
        
    header('Location: '$root $name_use);
        
    mysql_close($con);
        exit;

    Also, my browser doesn't "rewrite" the URL. it says it can't find the URL. I don't know what's wrong. Help?

    Code:
    RewriteEngine  on
    RewriteRule ^/social/([^/]+)$ /user.php?user=$1


Bookmarks

Posting Permissions

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