var login = $("#head_reg_login_icon").val(); if(new RegExp("^[A-z0-9_-]{3,20}$").test(login)) alert(1); else alert(2);