using regex in bash conditional statement

Shell
pat="[0-9a-zA-Z ]"
if [[ $x =~ $pat ]]; then ...
Source

Also in Shell: