Jieunny์˜ ๋ธ”๋กœ๊ทธ

Unit 10. [์‹ค์Šต] ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ณธ๋ฌธ

CodeStates/Training

Unit 10. [์‹ค์Šต] ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

Jieunny 2023. 1. 10. 13:12

๐Ÿ“ฃ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

1๏ธโƒฃ ์•„์ด๋””๋Š” 4๊ธ€์ž ์ด์ƒ์ด์–ด์•ผ ํ•œ๋‹ค.

โœ”๏ธ isMoreThan4Length(value) ํ•จ์ˆ˜ ๊ตฌํ˜„

โœ”๏ธ value์˜ ๊ธธ์ด๊ฐ€ 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ true, ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ false ๋ฆฌํ„ด

function isMoreThan4Length(value) {
  return value.length >= 4;
}

 

2๏ธโƒฃ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์ˆซ์ž์™€ ํŠน์ˆ˜๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด์•ผ ํ•œ๋‹ค.

โœ”๏ธ checkForm(value) ํ•จ์ˆ˜ ๊ตฌํ˜„

โœ”๏ธ value์— ์ˆซ์ž์™€ ํŠน์ˆ˜๋ฌธ์ž๊ฐ€ ๊ฐ๊ฐ ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋˜๋ฉด true ๋ฆฌํ„ด

โœ”๏ธ isNaN(value) ํ•จ์ˆ˜๋Š” is Not a Number๋กœ, ๋ฌธ์ž์—ด์— ์ˆซ์ž๊ฐ€ ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋  ๊ฒฝ์šฐ true๋ฅผ ๋ฆฌํ„ด

let special = /[~!@#$%^&*()_+|<>?:{}]/; // ํŠน์ˆ˜๋ฌธ์ž ์ •๊ทœ์‹ ์‚ฌ์šฉ

function checkForm(value) { // ๋น„๋ฐ€๋ฒˆํ˜ธ ํ˜•์‹ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜
  let numberIn = false;
  let specialIn = false;
  for(let i=0; i<value.length; i++){	// ํ•˜๋‚˜ํ•˜๋‚˜ ๋Œ๋ฉด์„œ ์ˆซ์ž ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋ฌ๋Š”์ง€ ํ™•์ธ.
    if(isNaN(value[i]) === false){
      numberIn = true;
    }
  }
  if(special.test(value)){	// ํŠน์ˆ˜๋ฌธ์ž ํฌํ•จํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ
    specialIn = true;
  }
  if(numberIn === true && specialIn === true){
    return true;
  }
  else{
    return false;
  }
}

 

 

3๏ธโƒฃ ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ๊ฐ’์€ ์ผ์น˜ํ•ด์•ผ ํ•œ๋‹ค.

โœ”๏ธ isMatch(password1, password2) ํ•จ์ˆ˜ ๊ตฌํ˜„

โœ”๏ธ password1๊ณผ password2๊ฐ€ ์ผ์น˜ํ•˜๋ฉด true ๋ฆฌํ„ด

function isMatch (password1, password2) { // ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์ด ๊ฐ™์€์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜
  if(password1 === password2){
    return true;
  }
  else{
    return false;
  }
}

 

 

4๏ธโƒฃ ํ•„์ˆ˜ ์ž…๋ ฅ๋ž€์— ๋นˆ์นธ์ด ์žˆ์œผ๋ฉด 'ํšŒ์›๊ฐ€์ž…' ๋ฒ„ํŠผ์ด ๋น„ํ™œ์„ฑํ™”๋˜๊ณ  ๋นˆ์นธ์ด ์—†์œผ๋ฉด 'ํšŒ์›๊ฐ€์ž…' ๋ฒ„ํŠผ์ด ํ™œ์„ฑํ™” ๋œ๋‹ค.

โœ”๏ธ isFull() ํ•จ์ˆ˜ ๊ตฌํ˜„

function isFull() { 
  if(
    (elInputUsername.value.length > 0 &&
    elInputPassword.value.length > 0 &&
    elInputRePassword.value.length > 0 
    )
  ){
    elSignupBtn.classList.add('isActived');
  }
  else {
    elSignupBtn.classList.remove('isActived');
  }
}

 

 

5๏ธโƒฃ ํ•„์ˆ˜ ์ž…๋ ฅ๋ž€์— ๋นˆ์นธ์ด ์žˆ์œผ๋ฉด alert์ฐฝ์„ ๋„์šด๋‹ค.

โœ”๏ธ alertFull() ํ•จ์ˆ˜ ๊ตฌํ˜„

function alertFull() {
  if(
    (elInputUsername.value.length > 0 &&
    elInputPassword.value.length > 0 &&
    elInputRePassword.value.length > 0)
  ){
    return true;
  }
  else{
    alert("์ •๋ณด๋ฅผ ๋ชจ๋‘ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.");
    return false;
  } 
}

 

 

5๏ธโƒฃ .onkeyup ์‚ฌ์šฉํ•ด์„œ ํ‚ค๋ณด๋“œ๋กœ ์ž…๋ ฅํ• ๋•Œ ๋งˆ๋‹ค ์‹คํ–‰๋˜๊ฒŒ ๊ตฌํ˜„

elPhoneNumber1.onkeyup = function() {
  if(isNumber(elPhoneNumber1.value) === false){	// ์ „ํ™”๋ฒˆํ˜ธ์— ์ˆซ์ž๋งŒ ์žˆ๋Š”์ง€ ํ™•์ธ
    console.log(elPhoneNumber1.value);
    elInputNumberMessage.classList.remove('hide');
  }
  else {
    elInputNumberMessage.classList.add('hide');
  }
  isFull();
}

 

 

6๏ธโƒฃ ์ˆซ์ž์ธ์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜

๐Ÿšจ 'e'๋ฅผ ์ˆซ์ž๋กœ ํƒ์ง€ํ•˜๋Š” ์˜ˆ์™ธ ์ƒํ™ฉ ๋ฐœ์ƒ

// ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž์ธ์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜
function isNumber(value) {  
  if(isNaN(value) === true){
    return false;
  }
  else {
    return true;
  }
}

 

 

7๏ธโƒฃ ์ „ํ™”๋ฒˆํ˜ธ ๋งˆ์ง€๋ง‰ ์นธ ์ž…๋ ฅ ์ด๋ฒคํŠธ

โœ”๏ธ ์ฒซ๋ฒˆ์งธ, ๋‘๋ฒˆ์งธ์นธ๋„ ๋˜‘๊ฐ™์ด ๊ตฌํ˜„(์„ธ๋ฒˆ ๋‹ค 1,2,3๋ฒˆ์งธ ์นธ์„ ๋ชจ๋‘ ํ™•์ธํ•ด์ค˜์•ผ ์˜ˆ์™ธ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.)

// ์ „ํ™”๋ฒˆํ˜ธ ๋งˆ์ง€๋ง‰ ์นธ ์ž…๋ ฅํ•  ๋•Œ ์ด๋ฒคํŠธ(๋‘,์„ธ๋ฒˆ์งธ๋„ ๊ฐ™์ด ํ™•์ธ)
elPhoneNumber3.onkeyup = function() {
  if(isNumber(elPhoneNumber3.value) === false){
    console.log(elPhoneNumber3.value);
    elInputNumberMessage.classList.remove('hide');
  }
  else if(isNumber(elPhoneNumber2.value) === true && isNumber(elPhoneNumber1.value) === true && isNumber(elPhoneNumber3.value) === true) {
    elInputNumberMessage.classList.add('hide');
  }
  isFull();
}

 

๐Ÿ“ฃ ์‹คํ–‰ ํ™”๋ฉด

โžฐ CSS ๋Š” ์ถ”ํ›„์— ๋” ์ˆ˜์ •ํ•  ์˜ˆ์ •