아이디에 이어 비밀번호 정규식을 적용하고 있는데
이런 오류가 났다
join:187 Uncaught TypeError: Cannot read properties of undefined (reading 'match')
at pwCheck (join:187)
at HTMLInputElement.onblur (join:130)
Uncaught TypeError - 검색해보니 이 오류는
id값과 name의 값이 같아서 생기는 오류라고 한다.
헷갈릴까봐 id name값을 똑같이 쓰는 편인데
이런 오류가 뜰 줄이야!!
어쨌든 긴가민가 하면서 name값과 id값을 다르게 주니까 성공하였다.
비밀번호 정규식은 소문자 8~20자리 숫자 특수기호를 포함해야 지나갈 수 있다.
<script>
function pwCheck(){
const pw = document.getElementById('pw').value;
const pwResult = document.getElementById('pw_input_result');
const exp2 = /^(?=.*[a-z])(?=.*\d)(?=.*[-_!*])[a-z\d-_!*]{8,20}$/;
if(pw.match(exp2)){
pwResult.innerHTML = '좋습니다';
pwResult.style.color = 'green';
}else{
pwResult.innerHTML = '8~20자리 소문자, 특수기호(-_!*), 숫자 포함해주세요';
pwResult.style.color = 'red';
}
}
</script>
body에서
<label id="m_password" class="text-start">비밀번호</label>
<input class="form-control" type="password" name="m_password" id="pw"
placeholder="비밀번호 입력" onblur="pwCheck()" required>
<div id="pw_input_result"></div>
Uncaught TypeError... 잊지않겠다