Currency Input Mask

by Andrew Stoker

HTML

<script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>
<p>Try copy pasting the following value: 12345.67</p>
    
Currency (Will Truncate): <input id="trucated" />
<br>
Currency (Won't Truncate): <input id="good" />

JavaScript

$('#trucated').inputmask("numeric", {
    radixPoint: ".",
    groupSeparator: ",",
    digits: 2,
    autoGroup: true,
    prefix: '$', //No Space, this will truncate the first character
    rightAlign: false,
    oncleared: function () { self.Value(''); }
});
$('#good').inputmask("numeric", {
    radixPoint: ".",
    groupSeparator: ",",
    digits: 2,
    autoGroup: true,
    prefix: '$ ', //Space after $, this will not truncate the first character.
    rightAlign: false,
    oncleared: function () { self.Value(''); }
});