If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > $email

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-19-04, 09:41
mvillan mvillan is offline
Registered User
 
Join Date: Dec 2003
Location: Ogden Utah
Posts: 34
Red face $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
Reply With Quote
  #2 (permalink)  
Old 03-19-04, 11:14
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #3 (permalink)  
Old 03-19-04, 12:24
mvillan mvillan is offline
Registered User
 
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.


Quote:
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
Reply With Quote
  #4 (permalink)  
Old 03-19-04, 12:25
mvillan mvillan is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 03-19-04, 13:29
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #6 (permalink)  
Old 03-19-04, 13:51
mvillan mvillan is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 03-19-04, 16:13
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
I work with computer since 1982, and with Unix for 6 years.
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On