Text-mask: Letters only doesn't work properly with React 16.

Created on 6 Feb 2019  路  1Comment  路  Source: text-mask/text-mask

Hi.

Im using ([a-zA-Z\s])+ to get an only letters input mask but only accept one character.

image

image

Most helpful comment

Hi @fdorantesm, I think the mask prop of the MaskedInput component accepts an array of regular expressions that match a single character each, while your regular expression matches any number of characters.

For your use case you could consider passing a mask function instead.
Try with:

<ReactTextMask
  mask={s => Array.from(s).map(() => /[a-z]/i)}
  guide={false}
/>

Notice that we set guide to false so that when a newly added character does not match our regular expression it is not added to the input as an empty placeholder (e.g., _).

Have a look at the docs for more info ;)

>All comments

Hi @fdorantesm, I think the mask prop of the MaskedInput component accepts an array of regular expressions that match a single character each, while your regular expression matches any number of characters.

For your use case you could consider passing a mask function instead.
Try with:

<ReactTextMask
  mask={s => Array.from(s).map(() => /[a-z]/i)}
  guide={false}
/>

Notice that we set guide to false so that when a newly added character does not match our regular expression it is not added to the input as an empty placeholder (e.g., _).

Have a look at the docs for more info ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

intellix picture intellix  路  4Comments

msafi picture msafi  路  6Comments

refo picture refo  路  6Comments

douglasdtc picture douglasdtc  路  3Comments

lincolnthree picture lincolnthree  路  4Comments