-
-
Save QROkes/07263a0a8af68c7df0f28ced28f54f6b to your computer and use it in GitHub Desktop.
Check for valid domain name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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