Results 1 to 7 of 7

Thread: $email

  1. #1
    Join Date
    Dec 2003
    Location
    Ogden Utah
    Posts
    34

    Red face Unanswered: $email

    hello:

    If the user enters a space in the email field I want the shell not to allow that and prompt them of what they have done......... I cannot get it to work...... Any ideas???


    while echo "Enter email address EDI> \c" ; do
    read email
    case "$email" in
    *[!\ @\ .\ a-zA-Z]*) echo "Email Address cannot contain spaces"; continue;;
    "") echo "Empty fields not allowed"; continue;;
    *) if [ `expr "$email" : '.*'` -gt 50 ] ;
    then
    echo "Maximun 50 Characters permitted"
    else
    break
    fi;;
    esac
    done
    mvilla

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Try this modified version of your script (accep only alphanumeric characters and @ . - );
    Code:
    while echo "Enter email address EDI> \c" ; do
       read email
       case "$email" in
          *[!@.a-zA-Z0-9\-]*)
             echo "Email Address contains invalid characters"
             continue
             ;;
          "")
             echo "Empty fields not allowed"
             continue
             ;;
          *) if [ `expr length "$email"` -gt 50 ]
             then
                echo "Maximun 50 Characters permitted"
             else
                break
             fi
             ;;
       esac
    done
    Jean-Pierre.

  3. #3
    Join Date
    Dec 2003
    Location
    Ogden Utah
    Posts
    34

    Talking

    This is a much nicer solution I have implemented it into the script and it works great!!!! If I may ask for your input again. How would you have the shell look for an initial space at the beginning of the email address. For example:

    Enter email address EDI> milenko.villanueva@yahoo.com
    vs
    Enter email address EDI> milenko.villanueva@yahoo.com
    ===========
    The second email address has a couple of spaces in front of it so when it writes it to the email file ....... spaces go with it. It would be great if when some typed in spaces before the email address for the shell to prompt the user "Email Address contains invalid characters".

    Looking forward to your reply.


    Originally posted by aigles
    Try this modified version of your script (accep only alphanumeric characters and @ . - );
    Code:
    while echo "Enter email address EDI> \c" ; do
       read email
       case "$email" in
          *[!@.a-zA-Z0-9\-]*)
             echo "Email Address contains invalid characters"
             continue
             ;;
          "")
             echo "Empty fields not allowed"
             continue
             ;;
          *) if [ `expr length "$email"` -gt 50 ]
             then
                echo "Maximun 50 Characters permitted"
             else
                break
             fi
             ;;
       esac
    done
    mvilla

  4. #4
    Join Date
    Dec 2003
    Location
    Ogden Utah
    Posts
    34

    Talking

    You know the second email example should have several spaces .....although it does not show it.
    mvilla

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    I tried the script with bash and pdksh (Public Domain Ksh).
    In the both cases the read command removes the leading and trailing spaces and there is no way to determine if the user typed extra spaces.

    If your 'read' command doesn't removes thoses spaces, I think that the 'case' statement may go to the invalid case.

    Have you tried an address with spaces inside ?
    Jean-Pierre.

  6. #6
    Join Date
    Dec 2003
    Location
    Ogden Utah
    Posts
    34

    Talking

    In the both cases the read command removes the leading and trailing spaces and there is no way to determine if the user typed extra spaces.

    >> You are absolutely RIGHT!!! the read command does remove spaces. You know now I am wondering if someone has access to the source file that we are writing to and somehow modifying it {hopefully by accident}.

    Anyway how did you become so knowledgeble about the UX shells?
    mvilla

  7. #7
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    I work with computer since 1982, and with Unix for 6 years.
    Jean-Pierre.

Posting Permissions

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