React Input Mask how to put the ninth digit?

Asked

Viewed 4,193 times

3

I downloaded the package npm i React-text-Mask --save did the import in my Contact file but by default it comes out like this (55) 5555-5555 I’m having trouble putting this standard (55) 5 5555-5555

Could someone give me a suggestion on how to do this procedure ?

My code is like this:

<div class="row">
  <div class="input-field col s12">
    <MaskedInput
      mask={['(', /[1-9]/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
      className="form-control"
      placeholder="Enter a phone number"
      guide={false}
      id="my-input-id"
      onBlur={() => {}}
      onChange={() => {}}
      />
 </div>

  • You want to set the two standards?

  • Only one. This (55) 5 5555-5555

1 answer

5


Include a new digit /\d/ and a space in the pattern:

                              nono dígito  espaço
                                       ↓    ↓
mask={['(', /[1-9]/, /\d/, ')', ' ', /\d/, ' ', /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}

Browser other questions tagged

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