Guest User

Untitled

a guest
Feb 19th, 2020
116
110 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let input = JSON.parse(document.getElementById('arr').value);
  3.     let regExp = /^(?<name>[A-Z][a-z]* [A-Z][a-z]*) (?<phone>\+359([- ])\d(\3)\d{3}(\3)\d{3}) (?<email>[a-z0-9]+@[a-z]+\.[a-z]{2,3})$/g;
  4.     let result = document.getElementById('result');
  5.     input.forEach(e => {
  6.         let info = regExp.exec(e);
  7.         regExp.lastIndex = 0;
  8.         if (info !== null) {
  9.             let {name, phone, email} = info.groups;
  10.             let nameParagraph = document.createElement('p');
  11.             nameParagraph.textContent = `Name: ${name}`;
  12.             let phoneParagraph = document.createElement('p');
  13.             phoneParagraph.textContent = `Phone Number: ${phone}`;
  14.             let emailParagraph = document.createElement('p');
  15.             emailParagraph.textContent = `Email: ${email}`;
  16.             let endParagraph = document.createElement('p');
  17.             endParagraph.textContent = '- - -';
  18.             result.appendChild(nameParagraph);
  19.             result.appendChild(phoneParagraph);
  20.             result.appendChild(emailParagraph);
  21.             result.appendChild(endParagraph);
  22.         } else {
  23.             let invalidDataParagraph = document.createElement('p');
  24.             invalidDataParagraph.textContent = 'Invalid data';
  25.             result.appendChild(invalidDataParagraph);
  26.             let endParagraph = document.createElement('p');
  27.             endParagraph.textContent = '- - -';
  28.             result.appendChild(endParagraph);
  29.         }
  30.     });
  31. }
RAW Paste Data