Skip to content

Instantly share code, notes, and snippets.

@nwrox
Created July 24, 2017 17:16
Show Gist options
  • Save nwrox/34623dd1a18fe93ac74e078ab6eb9337 to your computer and use it in GitHub Desktop.
Save nwrox/34623dd1a18fe93ac74e078ab6eb9337 to your computer and use it in GitHub Desktop.
// capKey vem de uma iteração em um objeto
$('#div' + capKey).find('input')
.keydown(e => {
const key = e.key
, arrKeys = [
'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp','Backspace',
'Control', 'Delete', 'End', 'Home', 'Tab'
]
, input = $(e.currentTarget)
if(key === 'Backspace'){
delCount++
}
if(delCount > 4 && input.length < 5){
intDecimal = input.val().length
count = true
}
if(arrKeys.includes(key))
return
if(input.val() === ''){
count = true
intDecimal = 0
}
if((e.ctrlKey || e.metaKey) && ('a' || 'c' || 'v' || 'x')){
return
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105))
e.preventDefault()
if(intDecimal === 5){
input.val(input.val() + '.')
count = false
intDecimal = 0
}
if(input.val().length > 11)
e.preventDefault()
if(key.match(/[a-zA-Z]/))
e.preventDefault()
if(count)
intDecimal++
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment