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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -