From 484d684c9ef0543cd75489a313e4b70678175217 Mon Sep 17 00:00:00 2001 From: Dhanush Date: Mon, 2 Oct 2023 11:50:13 +0530 Subject: [PATCH 1/3] Create readme.md --- Regular Expressions/Email Address Validation/readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Regular Expressions/Email Address Validation/readme.md diff --git a/Regular Expressions/Email Address Validation/readme.md b/Regular Expressions/Email Address Validation/readme.md new file mode 100644 index 0000000000..4e9dda6e00 --- /dev/null +++ b/Regular Expressions/Email Address Validation/readme.md @@ -0,0 +1,9 @@ +## Email Address Validation + +This regular expression checks if the provided string matches the common pattern for email addresses. + +^[a-zA-Z0-9._%+-]+: Matches one or more characters that can be letters (both uppercase and lowercase), digits, dots, underscores, percent signs, or plus or hyphen signs at the start of the string. +@: Matches the "@" symbol. +[a-zA-Z0-9.-]+: Matches one or more characters that can be letters, digits, dots, or hyphens in the domain part of the email address. +\.: Matches a dot. +[a-zA-Z]{2,}$: Matches two or more letters at the end of the string, representing the top-level domain (TLD) of the email address. From ce92da6edd3d5637d8bd87aa4d169128690c6c43 Mon Sep 17 00:00:00 2001 From: Dhanush Date: Mon, 2 Oct 2023 11:51:05 +0530 Subject: [PATCH 2/3] Add files via upload --- Regular Expressions/Email Address Validation/isEmail.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Regular Expressions/Email Address Validation/isEmail.js diff --git a/Regular Expressions/Email Address Validation/isEmail.js b/Regular Expressions/Email Address Validation/isEmail.js new file mode 100644 index 0000000000..80acd850c3 --- /dev/null +++ b/Regular Expressions/Email Address Validation/isEmail.js @@ -0,0 +1,9 @@ +const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; + +const email = "example@email.com"; + +if (emailRegex.test(email)) { + console.log("Valid email address"); +} else { + console.log("Invalid email address"); +} From ba5f076e4e57f42ae3effbfe02c53cecc9a184b0 Mon Sep 17 00:00:00 2001 From: Laszlo <47461634+Lacah@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:10:08 +0200 Subject: [PATCH 3/3] Update readme.md Added a comment about the code only working in ES2021 --- Regular Expressions/Email Address Validation/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Regular Expressions/Email Address Validation/readme.md b/Regular Expressions/Email Address Validation/readme.md index 4e9dda6e00..d816fa8724 100644 --- a/Regular Expressions/Email Address Validation/readme.md +++ b/Regular Expressions/Email Address Validation/readme.md @@ -2,6 +2,8 @@ This regular expression checks if the provided string matches the common pattern for email addresses. +**Please note that the code is based on ES2021, and as such, will not work in the global scope or scopes that are not ES2021 compatible.** + ^[a-zA-Z0-9._%+-]+: Matches one or more characters that can be letters (both uppercase and lowercase), digits, dots, underscores, percent signs, or plus or hyphen signs at the start of the string. @: Matches the "@" symbol. [a-zA-Z0-9.-]+: Matches one or more characters that can be letters, digits, dots, or hyphens in the domain part of the email address.