Question: Create a JavaScript program named email _ validator.js for validating email addresses using a regular expression. Implement an EmailValidator class with the following functionalities :
Create a JavaScript program named email validator.js for validating email addresses using a regular expression. Implement an EmailValidator class with the following functionalities
: Constructor: No parameters required.
validateEmail Method: Parameters: 'email' string Returns a boolean indicating whether the provided email address is valid according to the specified regular expression rules.The regular expression rules for a valid email address are as follows: The email address must contain exactly one @ symbol. The @ symbol must not be the first or last character in the email address. The part before the @ symbol must contain at least one character, consisting of letters, digits, dots hyphens or underscores The part after the @ symbol must contain at least one dot followed by two or more characters.Export the class as a module and import it into a class called emailtester.js Implement a simple program in this file using the test code provided.
Sample Usage:javascript Import the EmailValidator classconst EmailValidator requireEmailValidator ; Create an instance of EmailValidatorconst validator new EmailValidator; Validate email addressesconsole.logvalidatorvalidateEmailjohndoe@example.com; Output: true console.logvalidatorvalidateEmailinvalidemail@example; Output: false console.logvalidatorvalidateEmailemail@example.couk; Output: true console.logvalidatorvalidateEmailanotheremail@domain; Output: false
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
