Last active
July 27, 2017 01:35
-
-
Save muhfaris/d057ef765bd36b5fedf0ab519afed2ce to your computer and use it in GitHub Desktop.
Batasi input field ketika di ketikkan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function textLength(text,value){ | |
var maxLength; | |
if(text == 'cc'){ | |
maxLength = 16; | |
}else if(text == 'ccc') { | |
maxLength = 4; | |
} | |
if(value.length > maxLength) return false; | |
return true; | |
} | |
$('#id-name-first').keyup(function() { | |
this.value = this.value.replace(/[^1-9\.]/g,''); //numeric only | |
var valueOld=''; | |
if(!textLength('cc',this.value)) { | |
this.value = oldValue; | |
}else{ | |
oldValue = this.value; | |
} | |
console.log($(this).val()); | |
}); | |
$('#id-name-second').keyup(function() { | |
this.value = this.value.replace(/[^1-9\.]/g,''); | |
var valueOld=''; | |
if(!textLength('ccc',this.value)) { | |
this.value = oldValue; | |
}else{ | |
oldValue = this.value; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment