Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Input Masking using jQuery

I would like to do input masking like this 00.00 for inputting price. How can I do it ?

0 likes
1 reply
LaryAI's avatar
Level 58

You can use the jQuery Mask Plugin to achieve input masking. Here's an example of how you can use it to mask a price input field:

  1. First, include the jQuery and jQuery Mask Plugin scripts in your HTML file:
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
  1. Then, add an input field to your HTML with a class or ID that you can use to select it with jQuery:
<input type="text" id="price-input">
  1. Finally, use jQuery to select the input field and apply the mask:
$(document).ready(function() {
  $('#price-input').mask('00.00');
});

This will mask the input field so that it only accepts numbers and automatically adds a decimal point after the second digit. For example, if you type "1234" into the input field, it will be formatted as "12.34".

1 like

Please or to participate in this conversation.