<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="price" name="price" class="form-control"/>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function validMoney(money){
var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
if (reg.test(money)) {
return true;
}else{
return false;
};
}
$("#price").on('input propertychange',function(){
this.value = this.value.replace(/[^\d\.]/g, '');
this.value = this.value.replace(/^\./g,'');
this.value = this.value.replace(/\.{2,}/g,'.');
this.value = this.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
})
</script>
</body>
</html>