Wednesday, June 4, 2014

Jquery limit text in input box

$('#txtpassword').on('keyup', function() {
    limitText(this, 10)
});

function limitText(field, maxChar){
    var ref = $(field),
        val = ref.val();
    if ( val.length >= maxChar ){
        ref.val(function() {
            console.log(val.substr(0, maxChar))
            return val.substr(0, maxChar);       
        });
    }
}

No comments:

Post a Comment