Search code examples
shopenwrtbusybox

validate only alphabets using shell script in busybox


I want to validate a string which should only be Alphabets (Capital/Small). I can do it in Linux easily using Bash or Shell, but not able to validate in Busybox (OpenWRT). My piece of code is ...

#!/bin/sh
. /usr/share/libubox/jshn.sh
Info=$(cat /root/Info.json)
json_load "$Info"
json_get_var value plmn_description
echo "$value"
if [[ "$value" == [a-zA-Z] ]] ;then
    echo "Valid"
else
    echo "Invalid information"
fi

...


Solution

  • You can use case conditional construct like this:

    case "$value" in
      *[!a-zA-Z]*) echo invalid information ;;
                *) echo valid
    esac