Skip to content

Instantly share code, notes, and snippets.

@omernaci
Last active August 15, 2018 11:15
Show Gist options
  • Save omernaci/3dfa6c2fcaa6b41fb2aa9531cfdc9b47 to your computer and use it in GitHub Desktop.
Save omernaci/3dfa6c2fcaa6b41fb2aa9531cfdc9b47 to your computer and use it in GitHub Desktop.
JQuery Number Input First Character Disable Zero
...
<input onfocus="disableFirstCharZero('inputId')"></input>
...
function disableFirstCharZero(elementId) {
$ ('#' + elementId).on( 'input propertychange paste', function(e) {
var reg = /^0+/gi;
if ( this.value.match(reg) ) {
this.value = this.value.replace(reg, '');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment