Write a class for a checking account that validates it’s created with valid parameters. A CheckingAccount has a clientId, email, firstName, lastName all set trough the constructor and an array of products that is initially empty. Each parameter must meet specific requirements:
-
clientId – must be a string representing a 6-digit number; if invalid, throw a TypeError with the message "Client ID must be a 6-digit number"
-
email – must contain at least one alphanumeric character, followed by the @ symbol, followed by one or more letters or periods; all letters must be Latin; if invalid, throw a TypeError with message "Invalid e-mail"
-
firstName, lastName – must be at least 3 and at most 20 characters long, containing only Latin letters; if the length is invalid, throw a TypeError with message "{First/Last} name must be between 3 and 20 characters long"; if invalid characters are used, throw a TypeError with message "{First/Last} name must contain only Latin characters" (replace First/Last with the relevant word);
All checks must happen in the order in which they are listed – if more than one parameter is invalid, throw an error for the first encountered. Note that error messages must be exact.
Submit your solution containing a single class definition.
Examples:
Sample Input:
let acc = new CheckingAccount('1314', 'ivan@some.com', 'Ivan', 'Petrov')
Output:
TypeError: Client ID must be a 6-digit number
Sample Input:
let acc = new CheckingAccount('131455', 'ivan@', 'Ivan', 'Petrov')
Output:
TypeError: Invalid e-mail
Sample Input:
let acc = new CheckingAccount('131455', 'ivan@some.com', 'I', 'Petrov')
Output:
TypeError: First name must be between 3 and 20 characters long
Sample Input:
let acc = new CheckingAccount('131455', 'ivan@some.com', 'Ivan', 'P3trov')
Output:
TypeError: "First name must contain only Latin characters