From 8b55aa3f8ca3b5125e4b2b6b5b79717d15a89323 Mon Sep 17 00:00:00 2001 From: alanc Date: Wed, 31 Jul 2024 22:16:48 -0400 Subject: [PATCH] homework done --- session-01/basics.js | 7 +++++++ session-01/validators.js | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/session-01/basics.js b/session-01/basics.js index 190e930..021afdd 100644 --- a/session-01/basics.js +++ b/session-01/basics.js @@ -6,3 +6,10 @@ this is a multi line comment */ + +//console.log("Hello World") + +let age = 15; +console.log("My age is",age) +agqw = "twantiy" +console.log(agqw.charAt(0)) \ No newline at end of file diff --git a/session-01/validators.js b/session-01/validators.js index 56ea66d..c9a39ab 100644 --- a/session-01/validators.js +++ b/session-01/validators.js @@ -7,7 +7,15 @@ - username cannot contain special characters */ function validUsername(username) { - return; + let SpecialChars = /[!@#$%^&*.?]/; + if(username.length>2 && username.length <11){ + if(username.charAt(0).toUpperCase() != username.charAt(0).toLowerCase()){ + if(username.search(SpecialChars)== -1){ + return true; + } + } + } + return false; } /* @@ -17,7 +25,20 @@ function validUsername(username) { - password must contain at least 1 letter, 1 number, and 1 special character */ function validPassword(password) { - return; + let SpecialChars = /[!@#$%^&*.?]/; + let UpperLetter = /[a-z]/; + let LowerLetter = /[A-Z]/; + let Num = /[0-9]/; + if(password.length>9&&password.length<65){ + if(password.search(SpecialChars)!=-1){ + if(password.search(UpperLetter)!=-1 || password.search(LowerLetter)!=-1){ + if(password.search(Num)!=-1){ + return true; + } + } + } + } + return false; } module.exports = { validUsername, validPassword };