javascript - HTML 5 Currency format -


this question has answer here:

i using lots of html 5 input controls in pages. 1 of requirement have textbox currency feature. tried this:

<input type="number" pattern="(d{3})([.])(d{2})" /> 

this allows me type values 10,000.00

but still not meeting requirements. want if user types in 10000 should convert currency format 10,000 onblur.

and when read value input type in javascript, should give me float instead of string value cannot use calculate without parsing.

here's workaround additional input type="text":

http://jsfiddle.net/uevv6/2/

html

<input type="text" id="userinput" pattern="[0-9]*"> <br> <input type="number" id="number"> 

js

document.getelementbyid("userinput").onblur =function (){          //number-format user input     this.value = parsefloat(this.value.replace(/,/g, ""))                     .tofixed(2)                     .tostring()                     .replace(/\b(?=(\d{3})+(?!\d))/g, ",");      //set numeric value number input     document.getelementbyid("number").value = this.value.replace(/,/g, "")  } 

regex here how print number commas thousands separators in javascript


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -