Skip to content

Instantly share code, notes, and snippets.

@QROkes
Created April 7, 2019 21:36
Show Gist options
  • Save QROkes/07263a0a8af68c7df0f28ced28f54f6b to your computer and use it in GitHub Desktop.
Save QROkes/07263a0a8af68c7df0f28ced28f54f6b to your computer and use it in GitHub Desktop.
Check for valid domain name
# Only numerals 0-9, basic Latin letters, both lowercase and uppercase, hyphen.
[[ $domain =~ ^[\.0-9A-Za-z\-]+$ ]] || domfail="true"
# Check Lenght
[[ ${#domain} -gt 67 ]] && domfail="true"
# Can not start or end with a hyphen
[[ $(echo "${domain}" | cut -c-1) == "-" || $(echo "${domain}" | rev | cut -c-1) == "-" ]] && domfail="true"
# Can not contain two points together and can not start or end with a point
[[ $domain == *..* || $(echo "${domain}" | cut -c-1) == "." || $(echo "${domain}" | rev | cut -c-1) == "." ]] && domfail="true"
[[ $domfail == "true" ]] && echo "[WARNING] Domain names can only contain letters, numbers or a hyphen; can not start or end with a hyphen and can be up to 67 characters long."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment