SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Location
    Cairns, Australia
    Posts
    762
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help validating username

    Hi guys,

    I am trying to validate a username input on my form using regular expression.

    The username can only have letters, numbers, underscores a single period. I dont want them to be able to use spaces and caps (possibly converting all chars to lowercase?)


    Can anyone help?

  2. #2
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Location
    Cairns, Australia
    Posts
    762
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it sorted using:

    PHP Code:
    // check for a valid username
    $pattern "/^([a-zA-Z0-9._])+$/"
    if(!
    preg_match($pattern,$_POST['username'])) { 
    $errors[] = 'Please enter a valid username.';
    } else { 
    // if it passes validation, convert to lowercase 
    $username strtolower($username);




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
  •