** HTML
<input type='text' name='currency' id='currency' class='form-control'>
Nhập 25500 -> thành 25.500
** PHP
Code php lấy lại giá trị: 25500
$currency = str_replace('.', '', $_POST['currency']);
** JS
<script type="text/javascript">
$("#currency").on("input", function () {
// Chỉ giữ lại số
let value = $(this).val().replace(/\D/g, "");
// Format 25.500
if (value !== "") {
value = Number(value).toLocaleString("vi-VN");
}
$(this).val(value);
});
</script>
Không có nhận xét nào:
Đăng nhận xét