Home > OS >  how to add xxxxx format in inputmask with html input pattern?
how to add xxxxx format in inputmask with html input pattern?

Time:06-10

Input mask is by default '_ _ _ _ _' this format with html pattern. My requirement is in zipcode input, I want to change above pattern to 'xxxxx' this format.

here is my code

<input type="text" id="zipcode" pattern="[0-9]{5}" minlength="5" maxlength="5" required />

js code

$('#zipcode').inputmask('99999');
// if I give number format in input mask, it is working good with '_ _ _' this format. But I want to show 'x' format.

$('#zipcode').inputmask('xxxxx');

Is there any way to change the format from _ to x enter image description here

CodePudding user response:

You can pass in options to override the default underscore - https://github.com/RobinHerbots/Inputmask#placeholder-1

$('#zipcode').inputmask('99999',{ "placeholder": "x" })

CodePudding user response:

You could try changing pattern="[0-9]{5}" to pattern="x{5}"

My guess is that the library you're using (inputmask) is setting the default mask of _____. The pattern="[0-9]{5}" option allows a series of 5 digits which is why if you "give number format in input mask, it is working good."

A site like rubular might be a fun playground to see what's going on.

  • Related