SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    May 2005
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question a simple login script isuue...can u solve it?

    hi friends,
    i have designed a login script for the users....the user is supposed to get an error message, if he enters anything other than a digit or an alphabet...i did that as follows:

    PHP Code:
    if (!isset($p['username'])||(trim ($p['username']) == ''))
              {
    flag_error ('username''Please enter a username.');}
         elseif ((
    strlen($p['username'])<8) || (ereg ('[^a-zA-Z0-9]'$p['username'])))
              {
    flag_error ('username''The username you chose is not valid. ' .'Usernames must be atleast 8 characters long'.'Usernames may only contain letters, digits.');} 
    now i also want to give the user the facility to enter underscore(_) and a hyphen(-)
    in the username field....that is, he should get an error message if he enters anything other than a digit, alphabet, underscore and hyphen.how do i achieve this?kindly help....this newbie

    regards,
    navajes
    Last edited by navajes123; Jun 13, 2005 at 03:09.

  2. #2
    SitePoint Addict
    Join Date
    May 2005
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the way 2 do it: note the /-/_ that has been added inside the ereg() function

    PHP Code:
    if (!isset($p['username'])||(trim ($p['username']) == '')) 
              {
    flag_error ('username''Please enter a username.');} 
         elseif ((
    strlen($p['username'])<8) || (ereg ('[^a-zA-Z0-9/-/_]'$p['username']))) 
              {
    flag_error ('username''The username you chose is not valid. ' .'Usernames must be atleast 8 characters long'.'Usernames may only contain letters, digits.');} 

  3. #3
    SitePoint Addict
    Join Date
    May 2005
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry folks...the problem is not solved...

    if i make it / _/- in the ereg(),then no error is caught when / is entered in username....whereas if i make it \_\- in the ereg(),no error is caught when \ is entered in the username....so back to square one...

    how do i overcome the problem

  4. #4
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello there:

    Have you tried putting the '-' & '_' in front of the rest?
    [^-_a-zA-Z0-9]

    The '-' is treated differently (as a metacharacter) if not placed before all others.

    John

  5. #5
    SitePoint Addict
    Join Date
    May 2005
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    grateful 2 u......it works

  6. #6
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could help.

    I can't take all the credit, however, as I had a bit of help myself from this book -> http://www.amazon.com/exec/obidos/tg...books&n=507846.

    Highly recommended for all your regular expression needs.


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
  •