check type of input


/ Published in: Bash
Save to your folder(s)

checks for
number
character
alphanumeric


Copy this code and paste it in your HTML
  1. [[ -z "$1" ]] && echo "I cant work without an input" && exit 1
  2.  
  3. INPUT="$@"
  4.  
  5. [[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0
  6.  
  7. [[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0
  8.  
  9. [[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.