Register
It is currently Tue Sep 23, 2014 6:21 am

function to see if variable is alphabetic


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon May 16, 2005 8:37 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
Code:
### check to see if variable is alpha #####
#                                         #
#                                         #
#                                         #
### call like #############################
# if isAlpha $var                         #
# then                                    #
#    echo "alpha"                      #
# else                                    #
#    echo "non-alpha"                  #
# fi                                      #
###########################################
function isAlpha()
{
   Alpha='y'
   len=`echo ${#1}`
   for ((i=0; i<$len; i++))
   do
      val=`echo ${1:$i:1}`
      val=`echo $val | tr [:upper:] [:lower:]`
      echo $val | grep ^[a-z] > /dev/null
      retval=$?
      if [[ $retval -eq 1 ]]
      then
         Alpha='n'
         break
      fi
   done
   if [[ $Alpha = 'y' ]]
   then
      return 0
   else
      return 1
   fi
}
### end isAlpha ###


Top
 Profile WWW  
 PostPosted: Wed Nov 15, 2006 7:58 pm   

Joined: Wed Nov 15, 2006 7:56 pm
Posts: 5
Here is a shorter version of the isAlpha fuction:

Code:
function isAlpha()
{
   non=${1//[a-zA-Z]/}
   return ${#non}
}


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP