Please revise this code, only one comma will be accept.
<!doctype html>
<html>
<head>
<title>Online jQuery Editor</title>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
</head>
<body>
<input type="text" id="numberInput">
<script>
$(document).ready(function() {
$('#numberInput').on('change', function() {
// Get the current value of the input field
var inputValue = $(this).val();
// Remove any non-numeric characters and cast it to a number
var numericValue = Number(inputValue.replace(/[^\d,]/g, '').replace(',', '.'));
// Check if the numeric value is a valid number
if (!isNaN(numericValue)) {
// Format the value with space and comma
var formattedValue = numericValue.toLocaleString('fr-FR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
// Update the value of the input field with the formatted value
$(this).val(formattedValue);
}
});
});
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Online jQuery Editor</title>
<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
</head>
<body>
<input type="text" id="numberInput">
<script>
$(document).ready(function() {
$('#numberInput').on('change', function() {
// Get the current value of the input field
var inputValue = $(this).val();
// Remove any non-numeric characters and cast it to a number
var numericValue = Number(inputValue.replace(/[^\d,]/g, '').replace(',', '.'));
// Check if the numeric value is a valid number
if (!isNaN(numericValue)) {
// Format the value with space and comma
var formattedValue = numericValue.toLocaleString('fr-FR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
// Update the value of the input field with the formatted value
$(this).val(formattedValue);
}
});
});
</script>
</body>
</html>