From 446566f7fd02c5f957927d445efd918a96b62a1a Mon Sep 17 00:00:00 2001 From: Lana Trupkina Date: Wed, 17 Mar 2021 13:35:46 +0200 Subject: [PATCH 1/5] HW#5_Trupkina --- HW6(Async-RegExp)/HW6_Trupkina.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 HW6(Async-RegExp)/HW6_Trupkina.js diff --git a/HW6(Async-RegExp)/HW6_Trupkina.js b/HW6(Async-RegExp)/HW6_Trupkina.js new file mode 100644 index 0000000..f283f53 --- /dev/null +++ b/HW6(Async-RegExp)/HW6_Trupkina.js @@ -0,0 +1,19 @@ + +function validEmail() { + //Set the default value + let email = prompt('Type correctly email please', `example@gmail.com`); + const regexp_email = /^[A-z0-9_\.+-]+@[A-z0-9-]{3,10}\.[A-z0-9]{2,6}$/; + if (email === null) return undefined;//i catch cancellation + else if (regexp_email.test(email) === true) return alert('This is your Email:\n' + email); + return validEmail(); +} + +console.log(validPassword()); +function validPassword(pass) { + //Set the default value with Math.random() if user doesn't want to come up with password + let password = prompt('Type your password please', Math.floor(Math.random() * Math.floor(999999)) + 'Add!t'); + const regexp_pass = /^.*(?=.{8,})(?=.+[A-Z])(?=.+[a-z])(?=.*[!@#$%^&*?+=-]).*$/; + if (password === null) return undefined;//i catch cancellation + else if (regexp_pass.test(password) === true) return alert('This is your password:\n' + password); + return validPassword(); +} \ No newline at end of file From 9d74a1597735b399c505f6ec3eeb495f1d1e5076 Mon Sep 17 00:00:00 2001 From: Lana Trupkina Date: Fri, 19 Mar 2021 15:35:25 +0200 Subject: [PATCH 2/5] fixing of disadvantages --- HW6(Async-RegExp)/HW6_Trupkina.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/HW6(Async-RegExp)/HW6_Trupkina.js b/HW6(Async-RegExp)/HW6_Trupkina.js index f283f53..678a287 100644 --- a/HW6(Async-RegExp)/HW6_Trupkina.js +++ b/HW6(Async-RegExp)/HW6_Trupkina.js @@ -2,13 +2,12 @@ function validEmail() { //Set the default value let email = prompt('Type correctly email please', `example@gmail.com`); - const regexp_email = /^[A-z0-9_\.+-]+@[A-z0-9-]{3,10}\.[A-z0-9]{2,6}$/; + const regexp_email = /^([A-z0-9_\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/; if (email === null) return undefined;//i catch cancellation else if (regexp_email.test(email) === true) return alert('This is your Email:\n' + email); return validEmail(); } -console.log(validPassword()); function validPassword(pass) { //Set the default value with Math.random() if user doesn't want to come up with password let password = prompt('Type your password please', Math.floor(Math.random() * Math.floor(999999)) + 'Add!t'); @@ -16,4 +15,29 @@ function validPassword(pass) { if (password === null) return undefined;//i catch cancellation else if (regexp_pass.test(password) === true) return alert('This is your password:\n' + password); return validPassword(); -} \ No newline at end of file +} + +console.log(validPassword()); +//testing password: +// aaaaaaaaA# //true +// AAAAAAA22a# //true +// AAAAAAAAAA# //false +// aA# //false +// 2222222222A#//false +// 2222222222a#//false +// 22222222222 //false +// 2222222222# //false +// ############ //false + +console.log(validEmail()); +//testing email: +//example@gmail.com //true +//EXAMPLE@MAIL.RU //true +//EXam_p.l-e@gmaiL.Com //true +//EXam_p.l35e@gmaiL.Com //true +//@gmaiL.Com //false +//gss@Yandex.mojong //true +//gs@Yandex.mojong //false +//example @gmail.com //false +//example@356.ru //true +//example@356.333 //false \ No newline at end of file From a5dd20f98bbacc9374318f38c0b27251cba12a38 Mon Sep 17 00:00:00 2001 From: Lana Trupkina Date: Fri, 19 Mar 2021 16:23:02 +0200 Subject: [PATCH 3/5] done hw6 --- HW6(Async-RegExp)/HW6_Trupkina.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/HW6(Async-RegExp)/HW6_Trupkina.js b/HW6(Async-RegExp)/HW6_Trupkina.js index 678a287..7d9fef2 100644 --- a/HW6(Async-RegExp)/HW6_Trupkina.js +++ b/HW6(Async-RegExp)/HW6_Trupkina.js @@ -2,7 +2,7 @@ function validEmail() { //Set the default value let email = prompt('Type correctly email please', `example@gmail.com`); - const regexp_email = /^([A-z0-9_\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/; + const regexp_email = /^([\w\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/;//we can't use \w in domen name and sub name if (email === null) return undefined;//i catch cancellation else if (regexp_email.test(email) === true) return alert('This is your Email:\n' + email); return validEmail(); @@ -40,4 +40,6 @@ console.log(validEmail()); //gs@Yandex.mojong //false //example @gmail.com //false //example@356.ru //true -//example@356.333 //false \ No newline at end of file +//example@356.333 //false +//example@Flora-mix.ru //true +//exa23@44m.p-le@Flora-mix.ru //false - for all ()!@#$%^&*= From 4b1224212e3424215bcde9c071e3154cac060845 Mon Sep 17 00:00:00 2001 From: Lana Trupkina Date: Sat, 20 Mar 2021 20:00:52 +0200 Subject: [PATCH 4/5] for review: fixed mistakes --- HW6(Async-RegExp)/HW6_Trupkina.js | 87 +++++++++++++++++-------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/HW6(Async-RegExp)/HW6_Trupkina.js b/HW6(Async-RegExp)/HW6_Trupkina.js index 7d9fef2..0c13038 100644 --- a/HW6(Async-RegExp)/HW6_Trupkina.js +++ b/HW6(Async-RegExp)/HW6_Trupkina.js @@ -1,45 +1,54 @@ -function validEmail() { - //Set the default value - let email = prompt('Type correctly email please', `example@gmail.com`); - const regexp_email = /^([\w\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/;//we can't use \w in domen name and sub name - if (email === null) return undefined;//i catch cancellation - else if (regexp_email.test(email) === true) return alert('This is your Email:\n' + email); - return validEmail(); +let email = ['example@gmail.com', //true + 'EXAMPLE@MAIL.RU', //true + 'EXam_p.l-e@gmaiL.Com', //true + 'EXam_p.l35e@gmaiL.Com', //true + '@gmaiL.Com', //false + 'gss@Yandex.mojong', //true + 'gs@Yandex.mojong', //false + 'example @gmail.com', //false + 'example@356.ru', //true + 'example@356.333', //false + 'example@Flora-mix.ru', //true + 'exa23@44m.p-le@Flora-mix.ru' //false - for all ()!@#$%^&*= +]; +console.log(validEmail(email)); +function validEmail(mail) { + const regexp_email = /^([\w\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/;//we can't use \w in domen name and sub name because '_' included + for (const iterator of mail) { + //console.log(`${iterator}: ${regexp_email.test(iterator) === true}`);//can be write shorter + if (regexp_email.test(iterator) === true) { + console.log(`${iterator}: true`); + } + else { + console.log(`${iterator}: false`); + }; + } } +let password = ['aaaaaaaaA#', //true + 'AAAAAAA22a#', //true + 'парОль3%', //false + 'passwOrd3%', //true + 'AAAAAAAAAA#', //false + 'aA#', //false + '2222222222A#', //false + '2222222222a#', //false + '22222222222', //false + '2222222222#', //false + '############' //false +]; +console.log(validPassword(password)); function validPassword(pass) { - //Set the default value with Math.random() if user doesn't want to come up with password - let password = prompt('Type your password please', Math.floor(Math.random() * Math.floor(999999)) + 'Add!t'); + /* only Latin and numbers, and a special character are allowed " ?,!, @, -, +, = ". + Large and small letters must be present, the password is at least 8 characters long */ const regexp_pass = /^.*(?=.{8,})(?=.+[A-Z])(?=.+[a-z])(?=.*[!@#$%^&*?+=-]).*$/; - if (password === null) return undefined;//i catch cancellation - else if (regexp_pass.test(password) === true) return alert('This is your password:\n' + password); - return validPassword(); + for (const iterator of pass) { + if (regexp_pass.test(iterator) === true) { + console.log(`${iterator}: true`); + } + else { + console.log(`${iterator}: false`); + } + } } - -console.log(validPassword()); -//testing password: -// aaaaaaaaA# //true -// AAAAAAA22a# //true -// AAAAAAAAAA# //false -// aA# //false -// 2222222222A#//false -// 2222222222a#//false -// 22222222222 //false -// 2222222222# //false -// ############ //false - -console.log(validEmail()); -//testing email: -//example@gmail.com //true -//EXAMPLE@MAIL.RU //true -//EXam_p.l-e@gmaiL.Com //true -//EXam_p.l35e@gmaiL.Com //true -//@gmaiL.Com //false -//gss@Yandex.mojong //true -//gs@Yandex.mojong //false -//example @gmail.com //false -//example@356.ru //true -//example@356.333 //false -//example@Flora-mix.ru //true -//exa23@44m.p-le@Flora-mix.ru //false - for all ()!@#$%^&*= From cf8038be65886ccfe71c1ba7dbaf75f41019c1bd Mon Sep 17 00:00:00 2001 From: Lana Trupkina Date: Thu, 25 Mar 2021 11:47:41 +0200 Subject: [PATCH 5/5] fixed: wrong name, dead code, unnecessary checking --- HW6(Async-RegExp)/HW6_Trupkina.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/HW6(Async-RegExp)/HW6_Trupkina.js b/HW6(Async-RegExp)/HW6_Trupkina.js index 0c13038..37ad1ef 100644 --- a/HW6(Async-RegExp)/HW6_Trupkina.js +++ b/HW6(Async-RegExp)/HW6_Trupkina.js @@ -12,12 +12,11 @@ let email = ['example@gmail.com', //true 'example@Flora-mix.ru', //true 'exa23@44m.p-le@Flora-mix.ru' //false - for all ()!@#$%^&*= ]; -console.log(validEmail(email)); -function validEmail(mail) { +console.log(checkEmail(email)); +function checkEmail(mail) { const regexp_email = /^([\w\.+-]{3,})+@[A-z0-9-]{3,10}\.[A-z]{2,6}$/;//we can't use \w in domen name and sub name because '_' included for (const iterator of mail) { - //console.log(`${iterator}: ${regexp_email.test(iterator) === true}`);//can be write shorter - if (regexp_email.test(iterator) === true) { + if (regexp_email.test(iterator)) { console.log(`${iterator}: true`); } else { @@ -38,13 +37,13 @@ let password = ['aaaaaaaaA#', //true '2222222222#', //false '############' //false ]; -console.log(validPassword(password)); -function validPassword(pass) { +console.log(checkPassword(password)); +function checkPassword(pass) { /* only Latin and numbers, and a special character are allowed " ?,!, @, -, +, = ". Large and small letters must be present, the password is at least 8 characters long */ const regexp_pass = /^.*(?=.{8,})(?=.+[A-Z])(?=.+[a-z])(?=.*[!@#$%^&*?+=-]).*$/; for (const iterator of pass) { - if (regexp_pass.test(iterator) === true) { + if (regexp_pass.test(iterator)) { console.log(`${iterator}: true`); } else {