Skip to content

Instantly share code, notes, and snippets.

@yannmadeleine
Created November 6, 2012 23:56
Show Gist options
  • Save yannmadeleine/4028544 to your computer and use it in GitHub Desktop.
Save yannmadeleine/4028544 to your computer and use it in GitHub Desktop.
truncated
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<form action="">
<input type="password" name="" id="pwd" maxlength="5" />
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
var pasted = function(){
var self = $(this);
var length = parseInt(self.attr('maxlength'));
self.data('orc-maxlength',length);
self.attr('maxlength',length + 1);
setTimeout(postPaste,500);
};
var postPaste = function(){
var self = $('#pwd');
var length = self.data('orc-maxlength');
self.removeData('orc-maxlength');
self.attr('maxlength', length);
if(self.val().length > length ){
console.log('truncated');
}
};
$('#pwd').bind('paste',pasted);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment