#!/bin/bash

read -p "Type smth: " text
if [[ $text =~ ^[[:alnum:]_]+$ ]]
then
    echo "ok"
else
    echo "not ok"
fi