Email 정규식으로 체크
1 2 3 4 5 6 7 8 9 10 11 12 |
function validEmail(resData, focus){ var regex=/^([\w-]+(?:\.[\w-]+)*)@@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-zA-Z]{2,6}(?:\.[a-zA-Z]{2})?)$/; if (!regex.test(resData)){ alert("이메일을 정확히 입력해 주세요."); jQuery("#"+focus).focus(); return false; } return true; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function validEmail(resData, focus){ var regex=/^([\w-]+(?:\.[\w-]+)*)@@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-zA-Z]{2,6}(?:\.[a-zA-Z]{2})?)$/; if (!regex.test(resData)){ alert("이메일을 정확히 입력해 주세요."); jQuery("#"+focus).focus(); return false; } return true; } </script> <input type="text" value="mail@mail.com.com" id="input01" onKeyUp="validEmail(this.value, 'input01');" /> |