-   Programming (
-   -   Checking for Alphabets (

gregarion 01-25-2010 02:01 PM

Checking for Alphabets

echo -n "read this also:"
read NewAuthor

if [ -z $( echo "$NewAuthor" | tr -d '[[:digit:]]' ) ] ; then
echo "its a digit"
echo "something else"

Hey guys , i am trying to do a search to check if the input is using alphabets and nothing else. I tried using [[:digit:]] and [[:alpha:]] but none seems to work

When i use digit, it read 22.k as alphabet and not as a wrong syntax.
For alpha , it does not allow me to input data which has spaces such as " hello world". how can i solve this issue.

David the H. 01-25-2010 02:27 PM

Assuming bash:


if [[ $testvar =~ [[:digit:]] ]]; then
    echo "String contains numbers."
    echo "No numbers found."

Of course, just using [[:digit:]] only won't match non-alphabetical characters either, like punctuation marks or foreign scripts. You'll have to modify it for that.

All times are GMT -5. The time now is 01:13 PM.