cleave.js demo

cleave.js demo

by willystyle

HTML

<script src="https://nosir.github.io/cleave.js/dist/cleave.min.js"></script>
<script src="https://nosir.github.io/cleave.js/dist/cleave-phone.i18n.js"></script>
<div class="container">
    <input class="input-numeral" placeholder="Enter numeral" />    
    <button class="button-number">show real value</button>
    <div id="result">    
</div>

CSS

* {
    box-sizing: border-box;
}
.container {
    width: 200px;
}
button {
    margin-bottom: 15px;
    width: 100%;
    height: 24px;
    outline: none;
    -webkit-appearance: none;
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    background-color: #fff;
    font-size: 13px;
}
.input-credit-card {
    margin-bottom: 5px;
}
input {
    display: block;
    outline: none;
    -webkit-appearance: none;
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    background-color: #fff;
    line-height: 30px;
    vertical-align: middle;
    height: 33px;
    width: 100%;
    font-size: 14px;
    padding: 0 8px;
    margin-bottom: 15px;
}

.input-numeral {
    text-align: right;
}

body {
    font-family: sans-serif;
}

a,
a:hover {
    color: #999;
}

a {
    font-size: 14px;
    margin-top: 20px;
}

JavaScript

// numeral
var cleaveNumeral = new Cleave('.input-numeral', {
		prefix: '$',
    numeral: true,
    numeralThousandsGroupStyle: 'thousand'
});


document.querySelector('.button-number').addEventListener('click', function() {
	var input1 = document.querySelector('.input-numeral');
  console.log('input: ', input1.value);
  console.log('escaped input: ', input1.value.replace(/[$,]/g, ''));
  console.log('real value: ', cleaveNumeral.getRawValue());
	alert(cleaveNumeral.getRawValue());
});