Bash to ash port, character-matching problem

I'm trying to convert this working bash script into an Ash script,

 read -p "Username:" _username
   if ! [[ "$_username" =~ [^a-zA-Z0-9] ]]; then
   	 echo "Valid"
   else
    	 echo "INVALID"
   fi

However, Ash does not recognize the "=~" character.

How can I do this?
Also, is there a good reference guide, so I don't need to post all my questions here? I can't find anything!

The bash shell provides lots of extensions above and beyond what the POSIX standards require. The ash shell doesn't provide nearly as many extensions. If you use the standard as your shell programming guide, you should get by OK. A straight translation (getting rid of bash extensions) for your script would be:

printf "Username:"
read _username
if [ "$_username" = "${_username%[^a-zA-Z0-9]*}" ]
then    echo "Valid"
else    echo "INVALID"
fi

If your system allows alphanumeric characters other than characters in the Portable Filename Character Set in user names, you might want:

printf "Username:"
read _username
if [ "$_username" = "${_username%[^[:album:]]*}" ]
then    echo "Valid"
else    echo "INVALID"
fi

Hi.

This may be useful ... cheers, drl

checkbashisms | Free Development software downloads at SourceForge.net

I'd like to add that in any case, letting variable names start with underscores is a problematic practice, even if it is allowed. Consider:

_foo="bar"
echo $_foo

_="bar"
echo $_

I hope this helps.

bakunin

printf "Username:"; read _username
   if [[ "$_username" != *[!a-zA-Z0-9]* ]]; then
      echo "Valid"
   else
      echo "INVALID"
   fi

A case statement will work in any Bourne type shell. This also makes it easy to test for an empty variable..

printf "Username: "
read _username
case $_username in 
  (*[![:alnum:]]*|"") 
    echo "invalid" ;;
  (*) 
    echo "valid"
esac

Note that will also allow letters with accents like and
To exclude those, you could use (*[!a-zA-Z0-9]*|"") but that may not work properly because of a locale collation order...

--
Also note hat the proper negation character with character sets used in patterns is ! not ^ (even though it probably will work too)