Created
January 29, 2024 15:44
-
-
Save dcoppari/302658bdd7122ba24bee88939edbfdf1 to your computer and use it in GitHub Desktop.
Validate email formart and domain
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
#!/usr/bin/env bash | |
function valid_format { | |
local email=$1 | |
local regex="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$" | |
[[ $email =~ ${regex} ]] || return 1 | |
} | |
function valid_domain { | |
local fqdn=$1 | |
[[ $fqdn == *"."* ]] || return 1 | |
host $fqdn >/dev/null 2>&1 || return 1 | |
} | |
email=$1 | |
valid_format $email | |
if [[ $? == 0 ]]; then | |
domain="${email#*@}" | |
valid_domain $domain | |
if [[ $? == 0 ]]; then | |
echo "LEGIT!" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment