Allow only 2 decimal points entry to a textbox using javascript or jquery? -


i called class called test textbox. when entered first value e.g. first value 4., output coming 4.00. want restrict entry 2 decimal places.

$(".test").keyup(function (event) {     debugger;     this.value = parsefloat(this.value).tofixed(2); }); 

this small change code may suffice:

  this.value = this.value.replace (/(\.\d\d)\d+|([\d.]*)[^\d.]/, '$1$2'); 

essentially replace decimal point followed number of digits decimal point , first 2 digits only. or if non digit entered removes it.


Comments

Popular posts from this blog

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -