Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CheckingAccount {
- _clientId;
- _email;
- _firstName;
- _lastName;
- constructor(clientId, email, firstName, lastName) {
- this.clientId = clientId;
- this.firstName = firstName;
- this.lastName = lastName;
- }
- get clientId() {
- return this._clientId;
- }
- set clientId(value) {
- if (value.length !== 6) {
- throw new TypeError('Client ID must be a 6-digit number');
- }
- this._clientId = value;
- }
- get firstName() {
- return this._firstName;
- }
- set firstName(value) {
- this.nameValidation(value, 'First');
- this._firstName = value;
- }
- get lastName() {
- return this._lastName;
- }
- set lastName(value) {
- this.nameValidation(value, 'Last');
- this._lastName = value;
- }
- get email() {
- return this._email;
- }
- set email(value) {
- let patternEmail = /^[a-zA-Z0-9]+@[a-zA-Z.]+$/g;
- if (!patternEmail.test(value)) {
- throw new TypeError(`Invalid e-mail`);
- }
- this._email = value;
- }
- nameValidation(value, prop) {
- if (value.length < 3 || value.length > 20) {
- throw new TypeError(`${prop} name must be between 3 and 20 characters long`);
- }
- let patternName = /^[A-Za-z]+$/g;
- if (!patternName.test(value)) {
- throw new TypeError(`${prop} name must contain only Latin characters`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement