REGEX is /^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/
This is a regular expression which means a expression that is used to match a certain format. This is used to validate an email.
The use of the regular expression is used to validate the email and provide a email format to be used. Using regular expressions is a way to limit errors from users and get what is expected from the input
- Anchors
- Quantifiers
- OR Operator
- Character Classes
- Grouping and Capturing
- Bracket Expressions
- Greedy and Lazy Match
- Author
Any regular Expression all or most of these characteristics. Through the breakdown of the email regular expression it will demonstrate the different parts to a regular expression.
/^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/
The beginning of the regular expression we see the (^) sign which beings the regular expression. Then the second one which is ($) which is the end of the regular expression through these make up the anchors.
Then we have the (+) where it is grouping the email name , email address like yahoo or gmail and the .com. Also the {2,6} which is used to identify the character from then [a-z.].
It allows you to match any character from a character set. The \d which is used to match any single digit is a character class used in the email validator.
The groups are [a-z0-9_.-]+) which is for the email name and the second one is ([\da-z.-]+) for email label like gmail or yahoo. There is also a group for ([a-z.]{2,6}) to get the .com notation
Email validation includes the character sets of [a-z0-9_.-], which is for any letter a-z and is case sensitive. It also has a character (0-9) and the characters (_) , (-) , and (.) and has [\da-z.-] which is gores through a single digit from (0-9), any character a-z which is case sensitive, and the characters (.) and (-) [a-z.] goes through any character (a-z) case sensitive and the character (.).
The expression is greedy match because it has the (+) and the {2,6} elements in the expression. These give the greedy (+) matches many times and the {2,6} matches for the last group