简体   繁体   中英

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

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 在此处输入图像描述

您可以传入选项以覆盖默认下划线 - https://github.com/RobinHerbots/Inputmask#placeholder-1

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM