Enforcing the maxlength attribute on mobile browsers Enforcing the maxlength attribute on mobile browsers javascript javascript

Enforcing the maxlength attribute on mobile browsers


Try this one:

var $input = $('input')$input.keyup(function(e) {    var max = 5;    if ($input.val().length > max) {        $input.val($input.val().substr(0, max));    }});

jsFiddle here: http://jsfiddle.net/fttk2/1/


var max = 1input.addEventListener('keyup', function (event) {    event.target.value = event.target.value.substring(0, max)})


This problem is because predictive text is enabled on your keyboard, disable it and try again