Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CheckingAccount {
- constructor(clientId, email, firstName, lastName) {
- this.clientId = clientId;
- this.email = email;
- this.firstName = firstName;
- this.lastName = lastName;
- }
- set clientId(newClientId) {
- const clientPatern = /^\d{6}$/g;
- if (!clientPatern.test(newClientId)) {
- throw new TypeError('Client ID must be a 6-digit number');
- }
- this._clientId = newClientId;
- }
- get clientId() {
- return this.clientId;
- }
- set email(newEmail) {
- const emailPatern = /^[a-zA-Z0-9]+@[a-zA-Z.]+$/g;
- if (!emailPatern.test(newEmail)) {
- throw new TypeError('Invalid e-mail');
- }
- this._email = newEmail;
- }
- get email() {
- return this.email;
- }
- set firstName(newFirstName) {
- if (!(newFirstName.length >= 3 && newFirstName.length <= 20)) {
- throw new TypeError('First name must be between 3 and 20 characters long');
- }
- const pattern = /[a-zA-Z]/g;
- if (!pattern.test(newFirstName)) {
- throw new TypeError('First name must contain only Latin characters');
- }
- this._firstName = newFirstName;
- }
- get firstname() {
- return this._firstName;
- }
- set lastName(newLastName) {
- if (!(newLastName.length >= 3 && newLastName.length <= 20)) {
- throw new TypeError('Last name must be between 3 and 20 characters long');
- }
- const pattern = /[a-zA-Z]/g;
- if (!pattern.test(newLastName)) {
- throw new TypeError('Last name must contain only Latin characters');
- }
- this._lastName = newLastName;
- }
- get lastName() {
- return this._lastName;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment