SHARE
TWEET

Untitled

a guest Jun 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CheckingAccount{
  2.     constructor(clientId, email, firstName, lastName) {
  3.         this.clientId = clientId;
  4.         this.email = email;
  5.         this.firstName = firstName;
  6.         this.lastName = lastName;
  7.     }
  8.     get clientId() {
  9.         return this._clientID;
  10.     }
  11.     set clientId(value) {
  12.         let pattern = /^\d{6}$/;
  13.         if (!pattern.test(value)) {
  14.             throw new TypeError('Client ID must be a 6-digit number');
  15.         }
  16.         this._clientID;
  17.     }
  18.     get email() {
  19.         return this._email;
  20.     }
  21.  
  22.     set email(value) {
  23.         let pattern = /^\w+@[\w\\.]+$/;
  24.  
  25.         if (!pattern.test(value)) {
  26.             throw new TypeError('Invalid e-mail');
  27.         }
  28.  
  29.         this._email = value;
  30.     }
  31.     get firstName() {
  32.         return this._firstName;
  33.     }
  34.  
  35.     set firstName(value) {
  36.         if (value.length < 3 || value.length > 20) {
  37.             throw new TypeError('First name must be between 3 and 20 characters long');
  38.         }
  39.  
  40.         let pattern = /^[A-Za-z]+$/;
  41.  
  42.         if (!pattern.test(value)) {
  43.             throw new TypeError('First name must contain only Latin characters');
  44.         }
  45.  
  46.         this._firstName = value;
  47.     }
  48.     get lastName() {
  49.         return this._lastName;
  50.     }
  51.  
  52.     set lastName(value) {
  53.         let pattern = /^[A-Za-z]+$/;
  54.         if (value.length < 3 || value.length > 20) {
  55.             throw new TypeError('Last name must be between 3 and 20 characters long');
  56.         }
  57.  
  58.  
  59.         if (!pattern.test(value)) {
  60.             throw new TypeError('Last name must contain only Latin characters');
  61.         }
  62.  
  63.         this._lastName = value;
  64.     }
  65.  
  66. }
  67. let acc = new CheckingAccount('1314', 'ivan@some.com', 'Ivan', 'Petrov')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top