Is there an easy way to validate an input field size. Let us say a script is asking to enter 10 digits mobile number, how do I write a script to validate it is numeric and is 10 digits in length? I just need an easy way w/o using looks ...etc. Is there such a away ?
Here is what I have so far and it looks like it is working, but is there an easier way?
print -n "Enter your Mobile 10 digit number to turn off ....? " ; read mobile
if echo $mobile | egrep -q '^[0-9]+$' ; then
echo "You have entered = $mobile"
else
echo "IF-Invalid number <$mobile> entered. Entry must be numeric ..."
exit 255
fi
echo "..................."
case $mobile in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) echo "You have entered = $mobile" ;;
*) echo "Mobile number <$mobile> size entered is not a 10 digits number ...."
exit 255;;
esac
read mobile
if [[ "$mobile" != +([0-9]) ]]
then
# Not numeric
else
# Is numeric
fi
if [[ ${#mobile} -eq 10 ]]
then
# Is 10 digits
else
# Not 10 digits
fi
How do I search for 816444555 in the file and check if it starts with a # "Commented out" and if it does skip it. Else a # in front of it in the same input file?
If you're using bash or ksh, you could read -N10 mobile to read exactly 10 chars. mobile=${mobile//[^[:digit:]]/} will eliminate any non-digit character in mobile, so you could check its length or do any other check...