본문 바로가기

BLOG/JavaScript

email input 영어/숫자만 이메일에 유효한 특수문자 입력받게 하기

html코드

<input type="email" name="test" />

 

jquery 코드

$(function(){
  $('"input[name=test]').on('keyup', function(event){
    if (!(event.keyCode >=37 && event.keyCode<=40)) { 
      var inputVal=$(this).val();

      $(this).val(inputVal.replace(/[^a-z0-9@_.-]/gi,''));  
    } 
  });
});

 

영어/숫자 @-_. 을제외하고 한글입력 무시함