0

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.

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by Roybut
1

try

until [ $(echo "$myVar" | grep -e '^[a-zA-Z]*$') ]
  do
    read - p "Enter some text" myVar
  done
Votes + Comments
Thank you
0

try

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

Perfect. Thank you. I searched Google for an age but couldn't find this.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.