form-input-mask.mdx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. title: Input mask
  3. summary: An input mask is a used to clarify the input format required in a given field and is helpful for users, removing confusion and reducing the number of validation errors.
  4. description: Clarify input formats for users.
  5. ---
  6. ## Installation
  7. To be able to use the input mask in your application you will need to install the imask dependency. You can do this by running the following command:
  8. <TabsPackage name="imask" />
  9. And import or require:
  10. ```javascript
  11. import IMask from 'imask';
  12. ```
  13. You can also use the CDN link to include the script in your project:
  14. ```html
  15. <script src="https://cdn.jsdelivr.net/npm/imask"></script>
  16. ```
  17. If you struggle with the installation, you can find more information in the [IMask documentation](https://imask.js.org/guide.html#installation).
  18. ## Default markup
  19. Use an input mask in the fields where users have to enter their phone number, to make the formatting rules clear and help them avoid confusion.
  20. To create an input mask, add the `data-mask` attribute to the input element:
  21. ```html
  22. <input type="text" name="input-mask" class="form-control" data-mask="(00) 0000-0000" placeholder="(00) 0000-0000" autocomplete="off" />
  23. ```
  24. Look at the example below to see how the input mask works:
  25. ```html example centered columns={1}
  26. <label class="form-label">Telephone mask</label>
  27. <input type="text" name="input-mask" class="form-control" data-mask="(00) 0000-0000" data-mask-visible="true" placeholder="(00) 0000-0000" autocomplete="off" />
  28. ```
  29. ## More examples
  30. If you need more examples of input masks, you can find them in the [IMask documentation](https://imask.js.org/guide.html#masked-input).