Input Validation

Reply

Join Date: Oct 2008
Posts: 23
Reputation: Roybut is an unknown quantity at this point 
Solved Threads: 0
Roybut Roybut is offline Offline
Newbie Poster

Input Validation

 
0
  #1
Aug 8th, 2009
Hi,

I need to validate user input to ensure it is alphabet characters only. I know there must be a simple solution but evertything I have tried has either partially failed or totally failed.

At the moment, I have this:

until [ $(echo "$myVar" | grep -v '[^a-zA-Z]') ]
                do
                        read -p "Enter some text" myVar
                done

and it works but allows at least spaces (possibly other unwanted characters, too) and I can't use that. I know very little of grep so if some kind person will point out where I'm going wrong, I'll be most grateful.

Thanks.
Last edited by Roybut; Aug 8th, 2009 at 12:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 54
Reputation: ryuslash is an unknown quantity at this point 
Solved Threads: 10
ryuslash's Avatar
ryuslash ryuslash is offline Offline
Junior Poster in Training

Re: Input Validation

 
1
  #2
Aug 9th, 2009
try
  1. until [ $(echo "$myVar" | grep -e '^[a-zA-Z]*$') ]
  2. do
  3. read - p "Enter some text" myVar
  4. done
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: Roybut is an unknown quantity at this point 
Solved Threads: 0
Roybut Roybut is offline Offline
Newbie Poster

Re: Input Validation

 
0
  #3
Aug 10th, 2009
Originally Posted by ryuslash View Post
try
  1. until [ $(echo "$myVar" | grep -e '^[a-zA-Z]*$') ]
  2. do
  3. read - p "Enter some text" myVar
  4. done

Perfect. Thank you. I searched Google for an age but couldn't find this.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC