I'm using a Bash script to prompt users for several variables before continuing. If I want to create static validation rules and execute them on user inputs in an "a la carte" fashion, how would I go about doing that?
Example:
function q1 () {
echo "Do you have an answer?"
read input
# I know this is wrong but should get the idea across
chkEmpty($input)
chkSpecial($input)
}
function chkEmpty () {
if [[ $input = "" ]]; then
echo "Input required!"
# Back to Prompt
else
# Continue to next validation rule or question
fi
}
function chkSpecial () {
re="^[-a-zA-Z0-9\.]+$"
if ! [[ $input =~ $re ]]; then
echo "Cannot use special characters!"
# Back to prompt
else
# Continue to next validation rule or question
fi
}
function chkSize () {
etc...
}
etc...