jQuery - on text change while user typing or paste

Max Zag picture Max Zag · Jun 12, 2014 · Viewed 27.7k times · Source

I'm new to jQuery and I've tried to make something but I failed so here is my problem when the user type it works but when the user paste something didn't work !!

$(document).ready(function(){

        $('#username').keyup(username_check);
});

the username_check function :

function username_check(){  
var username = $('#username').val();
if(username == "" || username.length < 4){
alert("error");
}

the field :

<input type="text" id="username" name="username" required>

Answer

tymeJV picture tymeJV · Jun 12, 2014

If you want to capture all input events:

$('#username').on("input", username_check);