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.

try

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.