Tcomb-form-native: Mask for number input

Created on 24 Nov 2016  路  5Comments  路  Source: gcanti/tcomb-form-native

Is it possible to define a mask to a number input?

I would like to provide a currency and a phone number mask for some inputs

Most helpful comment

All 5 comments

Yes, you should define your custom templates: https://github.com/gcanti/tcomb-form-native#templates

Inside your template you can change what's actually displayed.

Please let me know if you need further help to build your template.

I am trying to use this for cel-phone masking and it works great for display and editing but validation always fails. I have the field defined as t.Number on which I apply this mask. Help appreciated

@vivekmago Not sure if I did it on right way, but I wanted to have something like exactly "999-999-999" mask.
So, to handle the validation, I'm using following code:

const formOptions = {
  stylesheet: appstyle,
  auto: 'none',
  fields: {
    phone: {
      keyboardType:'numeric',
      error: 'Please, provide correct phone number',
      placeholderTextColor: 'rgba(255,255,255,0.5)',
      placeholder: '123-456-789',
      template: PhoneMask
    },
  },
};

+

const Phone = t.subtype(t.String, (phone) => {
  const reg = /^\d{3}-\d{3}-\d{3}$/;
  return reg.test(phone);
});


let Form = t.form.Form;
let Login = t.struct({
  phone: t.Number,
  phone2:Phone
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

semirturgay picture semirturgay  路  4Comments

michaelbenker picture michaelbenker  路  3Comments

pocesar picture pocesar  路  4Comments

ishigamii picture ishigamii  路  3Comments

BogdanHossu picture BogdanHossu  路  6Comments