Last active 1736852850

dartokloning's Avatar dartokloning revised this gist 1736852850. Go to revision

1 file changed, 55 insertions

EmailValidation.sh(file created)

@@ -0,0 +1,55 @@
1 + #!/bin/bash
2 +
3 + #Email Format Validation:
4 + #- Uses a regular expression to check if the email address format is valid.
5 +
6 + #Domain Existence Check:
7 + #- Uses the dig command to look up the domain's DNS records.
8 + #- Ensures the domain has a valid DNS record.
9 +
10 + #Input and Validation:
11 + #- Prompts the user to enter an email address.
12 + #- Extracts the domain from the email address.
13 + #- Validates the email format and checks if the domain exists.
14 + #- Displays appropriate messages based on the validation and check results.
15 +
16 + # Function to validate the email format
17 + function validate_email_format() {
18 + local email="$1"
19 +
20 + if [[ "$email" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
21 + return 0
22 + else
23 + echo "Invalid email format."
24 + return 1
25 + fi
26 + }
27 +
28 + # Function to check if the email domain exists
29 + function check_domain_exists() {
30 + local domain="$1"
31 +
32 + if dig +short "$domain" | grep -q '^[0-9]'; then
33 + return 0
34 + else
35 + echo "Domain does not exist."
36 + return 1
37 + fi
38 + }
39 +
40 + # Get email input from the user
41 + read -p "Enter email: " email
42 +
43 + # Extract domain from email
44 + domain=$(echo "$email" | awk -F '@' '{print $2}')
45 +
46 + # Validate email format and check domain existence
47 + if validate_email_format "$email"; then
48 + if check_domain_exists "$domain"; then
49 + echo "Email is valid and domain exists."
50 + else
51 + echo "Email is valid, but domain does not exist."
52 + fi
53 + else
54 + echo "Invalid email format. Please try again."
55 + fi
Newer Older