jquery inputmask does not accept quantifier in "Validator" function

Asked

Viewed 262 times

1

I am trying to make a customAlias to use with jQuery Inputmask, but I am facing the following problem:

My input:

<input id="input-field-nome" data-inputmask="'alias':'customAlias'" type="text" data-rule-required="true" class="form-control required" placeholder="Nome e sobrenome">

Javascript:

 Inputmask.extendAliases({
    'customAlias': {
      autoUnmask: true,
      placeholder: "",
      mask: "a",
      definitions: { "a" : { validator: "[a-zA-Z]+" } }
    }
  });

  //initializing the plugin
  $(":input").inputmask({
    placeholder: ''
  });

I understood that the line validator: "[a-zA-Z]+" should work as follows: 'any letter once or more, but the quantifier + is not working. I can only insert a letter in the field.

I tried the following ways, but none solved:

"validator": "[a-zA-Z\+]", - I saw something like this on the plugin examples page.

"validator": "[a-zA-Z]\+", - I thought that escaping the + would be the solution, but no.

1 answer

2


a simple solution is to add the repeat attribute to your definition

Inputmask.extendAliases({
    'customAlias': {
      autoUnmask: true,
      placeholder: "",
      mask: "a",
      repeat: 100, // tamanho máximo do campo
      definitions: { "a" : { validator: "[a-zA-Z]" } }
    }
  });

I just think you forgot that you should be allowed to accept spaces, so I would change the mask to [a-zA-Z\s]

  • 1

    +1 and follows the fiddle =D

  • Good @Marcosregis, this solves my problem. Out of curiosity, you know why in the regex of Validator I can not use any quantifier? I tried '+', '*', '{1, 10}', '{10}' and nothing. It would be great if it worked

  • interestingly, here at my place, only with s worked. Already in the fiddle I needed to use s

  • 1

    @Victoralencarsantos I don’t use this plugin (I also use masks, but I use another plugin) and I don’t know exactly why. Apparently he does not use Validator as a de facto regex. He only accepts the qualifiers to then form the final regex.

  • Got it, thank you very much! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.