Code Monkey home page Code Monkey logo

react-native-masked-text's Introduction

react-native-masked-text

downloads Help Contribute to Open Source

logo

This is a simple masked text (normal text and input text) component for React-Native.

Alert

Hey guys!

Unfortunatelly I'm not developing js apps anymore. This repo will not receive updates anymore.

Supported Versions

React-native: 0.32.0 or higher

Install

npm install react-native-masked-text --save

Usage (TextInputMask)

For all the masks you will use in this way:

import { TextInputMask } from 'react-native-masked-text'

//...

<TextInputMask
  type={'type-of-the-mask'}
  options={
    {
      // the options for your mask if needed
    }
  }

  // dont forget to set the "value" and "onChangeText" props
  value={this.state.text}
  onChangeText={text => {
    this.setState({
      text: text
    })
  }}
/>

Cel Phone

Mask:

  • BRL (default): (99) 9999-9999 or (99) 99999-9999 (will detect automatically)
  • INTERNATIONAL: +999 999 999 999

If you need a different formatting, use the Custom mask =).

Sample code (source):

<TextInputMask
  type={'cel-phone'}
  options={{
    maskType: 'BRL',
    withDDD: true,
    dddMask: '(99) '
  }}
  value={this.state.international}
  onChangeText={text => {
    this.setState({
      international: text
    })
  }}
/>

Options

name type required default description
maskType string no maskType the type of the mask to use. Available: BRL or INTERNATIONAL
withDDD boolean no true if the mask type is BRL, include the DDD
dddMask string no (99) if the mask type is BRL, the DDD mask

Methods

You can get the unmasked value using the getRawValue method:

<TextInputMask
  type={'cel-phone'}
  options={{
    maskType: 'BRL',
    withDDD: true,
    dddMask: '(99) '
  }}
  value={this.state.international}
  onChangeText={text => {
    this.setState({
      international: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.phoneField = ref}
/>

//...

const unmasked = this.phoneField.getRawValue()
// in the mask: (51) 98765-4321
// unmasked: 51987654321

CPF

Mask: 999.999.999-99

Sample code (source):

<TextInputMask
  type={'cpf'}
  value={this.state.cpf}
  onChangeText={text => {
    this.setState({
      cpf: text
    })
  }}
/>

Methods

You can check if the cpf is valid by calling the isValid() method:

<TextInputMask
  type={'cpf'}
  value={this.state.cpf}
  onChangeText={text => {
    this.setState({
      cpf: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.cpfField = ref}
/>

// get the validation

const cpfIsValid = this.cpfField.isValid()
console.log(cpfIsValid) // boolean

You can get the unmasked cpf calling the getRawValue method:

const unmasked = this.cpfField.getRawValue()
// in the mask: 123.456.789-01
// unmasked: 12345678901

CNPJ

Mask: 99.999.999/9999-99

Sample code (source):

<TextInputMask
  type={'cnpj'}
  value={this.state.cnpj}
  onChangeText={text => {
    this.setState({
      cnpj: text
    })
  }}
/>

Methods

You can check if the cnpj is valid by calling the isValid() method:

<TextInputMask
  type={'cnpj'}
  value={this.state.cnpj}
  onChangeText={text => {
    this.setState({
      cnpj: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.cnpjField = ref}
/>

// get the validation

const cnpjIsValid = this.cnpjField.isValid()
console.log(cnpjIsValid) // boolean

You can get the unmasked cpf calling the getRawValue method:

const unmasked = this.cnpjField.getRawValue()
// in the mask: 99.999.999/9999-99
// unmasked: 99999999999999

Credit Card

Mask:

  • visa or master: 9999 9999 9999 9999 or 9999 **** **** 9999 (obfuscated)
  • amex: 9999 999999 99999 or 9999 ****** 99999 (obfuscated)
  • diners: 9999 999999 9999 or 9999 ****** 9999 (obfuscated)

Sample code (source)

<TextInputMask
  type={'credit-card'}
  options={{
    obfuscated: false,
    issuer: 'amex'
  }}
  value={this.state.creditCard}
  onChangeText={text => {
    this.setState({
      creditCard: text
    })
  }}
/>

Options

name type required default description
obfuscated boolean no false if the mask should be obfuscated or not
issuer string no visa-or-mastercard the type of the card mask. The options are: visa-or-mastercard, amex or diners

Methods

You can get the array containing the groups of the value value using the getRawValue method:

<TextInputMask
  type={'credit-card'}
  options={{
    obfuscated: false,
    issuer: 'amex'
  }}
  value={this.state.creditCard}
  onChangeText={text => {
    this.setState({
      creditCard: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.creditCardField = ref}
/>

//...

const unmasked = this.creditCardField.getRawValue()
// in the mask: 9874 6541 3210 9874
// unmasked: [9874, 6541, 3210, 9874]

Custom

Mask: defined by pattern

  • 9 - accept digit.
  • A - accept alpha.
  • S - accept alphanumeric.
  • * - accept all, EXCEPT white space.

Ex: AAA-9999

Sample code (source):

//
// SIMPLE
// 
<TextInputMask
  type={'custom'}
  options={{
    /**
     * mask: (String | required | default '')
     * the mask pattern
     * 9 - accept digit.
     * A - accept alpha.
     * S - accept alphanumeric.
     * * - accept all, EXCEPT white space.
    */
    mask: '999 AAA SSS ***'
  }}
  value={this.state.text}
  onChangeText={text => {
    this.setState({
      text: text
    })
  }}
  style={textInputStype}
/>


//
// ADVANCED
// 
<TextInputMask
  type={'custom'}
  options={{
    // required

    /**
     * mask: (String | required | default '')
     * the mask pattern
     * 9 - accept digit.
     * A - accept alpha.
     * S - accept alphanumeric.
     * * - accept all, EXCEPT white space.
    */
    mask: '999 AAA SSS ***',

    // optional

    /**
     * validator: (Function | optional | defaults returns true)
     * use this funcion to inform if the inputed value is a valid value (for invalid phone numbers, for example). The isValid method use this validator.
    */
    validator: function(value, settings) {
      return true
    },

    /**
     * getRawValue: (Function | optional | defaults return current masked value)
     * use this function to parse and return values to use what you want.
     * for example, if you want to create a phone number mask (999) 999-99-99 but want to get only
     * the numbers for value, use this method for this parse step.
    */
    getRawValue: function(value, settings) {
      return 'my converted value';
    },
    /**
     * translation: (Object | optional | defaults 9, A, S, *)
     * the dictionary that translate mask and value.
     * you can change defaults by simple override the key (9, A, S, *) or create some new.
    */
    translation: {
      // this is a custom translation. The others (9, A, S, *) still works.
      // this translation will be merged and turns into 9, A, S, *, #.
      '#': function(val) {
        if (val === ' ') {
          return val;
        }

        // if returns null, undefined or '' (empty string), the value will be ignored.
        return null;
      },
      // in this case, we will override build-in * translation (allow all characters)
      // and set this to allow only blank spaces and some special characters.
      '*': function(val) {
        return [' ', '#', ',', '.', '!'].indexOf(val) >= 0 ? val : null;
      }
    }
  }}
  value={this.state.text}
  onChangeText={text => {
    this.setState({
      text: text
    })
  }}
  style={textInputStype}
/>

Options

name type required default description
mask string YES The mask pattern
validator function no function that returns true the function that's validate the value in the mask
getRawValue function no return current value function to parsed value (like unmasked or converted)
translation object (map{string,function}) no 9 - digit, A - alpha, S - alphanumeric, * - all, except space The translator to use in the pattern

Datetime

Mask:

  • DD/MM/YYYY HH:mm:ss
  • DD/MM/YYYY
  • MM/DD/YYYY
  • YYYY/MM/DD
  • HH:mm:ss
  • HH:mm
  • HH

You can use - instead of / if you want.

Sample code (source):

<TextInputMask
  type={'datetime'}
  options={{
    format: 'YYYY/MM/DD'
  }}
  value={this.state.dt}
  onChangeText={text => {
    this.setState({
      dt: text
    })
  }}
/>

Options

name type required default description
format string YES The date format to be validated

Methods

You can check if the date is valid by calling the isValid() method:

<TextInputMask
  type={'datetime'}
  options={{
    format: 'YYYY/MM/DD'
  }}
  value={this.state.dt}
  onChangeText={text => {
    this.setState({
      dt: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.datetimeField = ref}
/>

// get the validation

const isValid = this.datetimeField.isValid()
console.log(isValid) // boolean

You can get the moment object from the date if it's valid calling the getRawValue method:

const momentDate = this.datetimeField.getRawValue()

Money

Mask: R$999,99 (fully customizable)

Sample code (source):

// SIMPLE
<TextInputMask
  type={'money'}
  value={this.state.simple}
  onChangeText={text => {
    this.setState({
      simple: text
    })
  }}
/>

// ADVANCED
<TextInputMask
  type={'money'}
  options={{
    precision: 2,
    separator: ',',
    delimiter: '.',
    unit: 'R$',
    suffixUnit: ''
  }}
  value={this.state.advanced}
  onChangeText={text => {
    this.setState({
      advanced: text
    })
  }}
/>

Options

name type required default description
precision number no 2 The number of cents to show
separator string no , The cents separator
delimiter string no . The thousand separator
unit string no R$ The prefix text
suffixUnit string no '' The sufix text

Methods

You can get the number value of the mask calling the getRawValue method:

<TextInputMask
  type={'money'}
  value={this.state.simple}
  onChangeText={text => {
    this.setState({
      simple: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.moneyField = ref}
/>

const numberValue = this.moneyField.getRawValue()
console.log(numberValue) // Number

// CAUTION: the javascript do not support giant numbers.
// so, if you have a big number in this mask, you could have problems with the value...

Only Numbers

Mask: accept only numbers

Sample code (source):

<TextInputMask
  type={'only-numbers'}
  value={this.state.value}
  onChangeText={text => {
    this.setState({
      value: text
    })
  }}
/>

Zip Code

Mask: 99999-999

Sample code (source):

<TextInputMask
  type={'zip-code'}
  value={this.state.value}
  onChangeText={text => {
    this.setState({
      value: text
    })
  }}
/>

Methods

You can get the unmasked value using the getRawValue method:

<TextInputMask
  type={'zip-code'}
  value={this.state.value}
  onChangeText={text => {
    this.setState({
      value: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.zipCodeField = ref}
/>

//...

const unmasked = this.zipCodeField.getRawValue()
// in the mask: 98765-321
// unmasked: 98765321

... Utils

Including the rawText in onChangeText [1.12.0+]

If you need the raw value in every text change, you can use the includeRawValueInChangeText.

It will provide the masked and the raw text in every text change.

<TextInputMask
  type={'cpf'}
  value={this.state.value}
  includeRawValueInChangeText={true}
  onChangeText={(maskedText, rawText) => {
    // maskedText: 123.456.789-01
    // rawText: 12345678901
  }}
/>

Getting the TextInput instance

If you want to get the TextInput raw component, use the getElement() method:

<TextInputMask
  type={'zip-code'}
  value={this.state.value}
  onChangeText={text => {
    this.setState({
      value: text
    })
  }}
  // add the ref to a local var
  ref={(ref) => this.zipCodeField = ref}
/>

//...

const textInput = this.zipCodeField.getElement()

Blocking user to add character

If you want, you can block a value to be added to the text using the checkText prop:

<TextInputMask
  //...
  /**
   * @param {String} previous the previous text in the masked field.
   * @param {String} next the next text that will be setted to field.
   * @return {Boolean} return true if must accept the value.
  */
  checkText={
    (previous, next) => {
      return next === 'your valid value or other boolean condition';
    }
  }
/>

Using custom text inputs

You can use this prop if you want custom text input instead native TextInput component:

const Textfield = MKTextField.textfield()
  .withPlaceholder('Text...')
  .withStyle(styles.textfield)
  .build();


<TextInputMask
  // ...

  // the custom text input component
  customTextInput={Textfield}

  // the props to be passed to the custom text input
  customTextInputProps={{
    style:{ width: '80%' },
    label:'Birthday'
  }}
/>

About the normal text input props

You can use all the normal TextInput props from React-Native, with this in mind:

  • onChangeText is intercepted by component.
  • value is intercepted by component.
  • if you pass keyboardType, it will override the keyboardType of masked component.

Code Samples

If you want, you can check the code samples in this repo:

react-native-masked-text-samples

Usage (TextMask)

import React, { Component } from 'react'

// import the component
import { TextMask } from 'react-native-masked-text'

export default class MyComponent extends Component {
    constructor(props) {
        super(props)
        this.state = {
            text: '4567123409871234'
        }
    }

    render() {
        // the type is required but options is required only for some specific types.
        // the sample below will output 4567 **** **** 1234
        return (
            <TextMask
                value={this.state.text}
                type={'credit-card'}
                options={{
                    obfuscated: true
                }}
            />
        )
    }
}

Props

The same of TextInputMask, but for React-Native Text component instead TextInput.
Warning: if the value not match the mask, it will not appear.

Methods

getElement(): return the instance of Text component.

Extra (MaskService)

If you want, we expose the MaskService. You can use it:

Methods

  • static toMask(type, value, settings): mask a value.
    • type (String, required): the type of the mask (cpf, datetime, etc...)
    • value (String, required): the value to be masked
    • settings (Object, optional): if the mask type accepts options, pass it in the settings parameter
  • static toRawValue(type, maskedValue, settings): get the raw value of a masked value.
    • type (String, required): the type of the mask (cpf, datetime, etc...)
    • maskedValue (String, required): the masked value to be converted in raw value
    • settings (Object, optional): if the mask type accepts options, pass it in the settings parameter
  • static isValid(type, value, settings): validate if the mask and the value match.
    • type (String, required): the type of the mask (cpf, datetime, etc...)
    • value (String, required): the value to be masked
    • settings (Object, optional): if the mask type accepts options, pass it in the settings parameter
  • static getMask(type, value, settings): get the mask used to mask the value

Ex:

import { MaskService } from 'react-native-masked-text'

var money = MaskService.toMask('money', '123', {
    unit: 'US$',
    separator: '.',
    delimiter: ','
})

// money -> US$ 1.23

Throubleshooting

  • If the es2015 error throw by babel, try run react-native start --reset-cache

Changelog

View changelog HERE

Thanks to

react-native-masked-text's People

Contributors

danielmaly avatar edcs avatar emiyake avatar enagorny avatar fabioh8010 avatar gabelerner avatar guisehn avatar helloncanella avatar luancurti avatar marcin-krysiak avatar mbezhanov avatar mmarkelov avatar notgiorgi avatar questionablequestion avatar rodineijf avatar rodrigoaweber avatar ronaldozanoni avatar schneems avatar svbutko avatar yamilquery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-masked-text's Issues

Font error on Andriod

Got a font family error when I used the Madoka template.

When I removed fontFamily: 'Arial', from /lib/Madoka.js, it uses my default font and no error.

label: {
backgroundColor: 'transparent',
fontFamily: 'Arial',
fontWeight: 'bold',
color: '#6a7989',
},

Possibility to omit type prop.

First of all, congratulations! it's a great library.

I just would like to request the possibility of omit the type prop or at least have a 'default' type so it would behave as a normal TextInput.

I'm building a custom component that will be used repeatedly in screen and sometimes, the prop is not needed, I mean, there's no mask to be validate.

Thanks in advance!

Using without mask

Hello,

Is it possible to use react-native-masked-text without the mask support, like a normal TextInput component inside React-Native?

[Question] input text for hashtags

I need an input text that only for hashtags value (unlimited hashtags ).
For example
#computer #game #sport #cpu

What i need.

  1. Only support alphanumeric and underscore .
  2. Unlimited hastags

How can I achieve it?
Thank you

Maximum amount of money?

Can you add an option that limits the amount of money you can input? I desperately need this feature.

Phone Format

North American phone numbers are like (999) 999-9999 and UK are different. Is there any way to format differently?

Support for Dates

Would be nice to have date support, I am working some on this for a project will see if I can make PR when done.

Optional characters in mask

hey,
first of all thanks for writing this, already saved me a lot of time :)

my question:
i need a mask that has a range of characters (vs a fixed amount).

_______________ / ______
^ 2-10 chars..... ^ 2-6 chars

is this possible with the current implementation?

i saw that for the cel-phone mask you have optional length (8 or 9 digits) but this functionality doesn't seem to be exposed to the custom-mask, or am I overlooking something here?

Reference error

Hi,

I'm trying to use ref props but when I'm using this.refs['field'] this error occurs:
screenshot_1497479579

My code:

<TextInputMask
  style={styles.input}
  keyboardType="numeric"
  ref={'cpf'}
  type={'cpf'}
  customTextInput={Input}
  value={this.props.profileEdit.cpf}
  onChangeText={value => this.props.changeProfileEditCpf(value)}
/>

My line error: console.log('CPF ', this.refs['cpf']);

ESLINT says use this.refs is deprecated.

RN version is 0.42.3

Any suggestion?

Problem with removing characters in the middle of the mask

v1.6.1
Having the following input

<TextInputMask
  type="custom"
  options={{ mask: '999 (99) 999 99 99' }}
/>

If I'll type 380934295576 the mask will display correct value like 380 (93) 429 55 76
But if I remove the 2 from the middle of the mask it will display 380 (93) 49,
instead of 380 (93) 495 57 6.

I've made some research and figured that problem is in passing value to tinymask that is already masked. in this particular case the value 380 (93) 49 55 76 is passed to the mask method and since space after 9 char doesn't match to numeric wildcard all the following chars are getting trimmed.

Suggest passing normalized value to mask

No inputText

Hello, I am very new on React Native. I put this component on my "login" component but the input do not shows up. I'm using native-base and follow the exact example but just the "Label" show on the form. Even the space where the input should be is not showing.

thanks

maxLenght set with the mask

At maxLenght you have to count the spaces and symbols of the mask together, it would be interesting that when putting the mask of, for example CPF, this already limited to 14 characters.

This avoids the effect of writing and erasing when you pass the mask border

Publish already built js on npm

Right now the source code is directly published, so my bundler now has to even build dependencies to use this package. It would be convenient if package was published pre-built.

fromMask to Value

is it possible to go from the masked value to the value without mask?

for instance:

R$ 10,20 to 10.20

MoneyMask not working as expected

import { MoneyMask } from 'react-native-masked-text/lib/masks'
static floatToString (value) {
    const mask = new MoneyMask()
    return mask.getValue(value, { unit: '' }, value)
}
expect(HMask.floatToString(0.01)).toBe('0,01') // OK
expect(HMask.floatToString(1.11)).toBe('1,11') // OK
expect(HMask.floatToString(1000.01)).toBe('1.000,01') // OK

folowing the the no OK values

expect(HMask.floatToString(1.10)).toBe('1,10') // "0,11"
expect(HMask.floatToString(1.90)).toBe('1,90') // "0,19"
"react-native-masked-text": "^1.6.3",

or am I missing something?

Using native TextInput onSubmitEditing() to focus on TextInputMask

<TextInput
  ref='input1'
  onSubmitEditing={ () => this.refs.input2.focus() } />

<TextInputMask
  ref='input2' />

After typing some text into input1 and pressing the submit button I get an error _this2.refs.input2.focus is not a function, it is undefined.

Is it possible to focus from TextInput to TexInputMask?

Suffix prevents backspace key function

I have a suffix that adds (a space and the euro sign) to the end of the textfield. When focusing the textfield, the cursor is right behind the suffix and the backspace key will no longer work. If I move the cursor after the actual value, everything is working as expected.

<TextInputMask style={ Styles.stylesheet.formItemTextInput }
               placeholder={ this.props.text }
               autoCapitalize={autoCapitalize}
               autoCorrect={autoCorrect}
               autoFocus={autoFocus}
               clearButtonMode="while-editing"
               onChangeText={ this.props.onChangeText }
               onSubmitEditing={this.props.doneButtonPressed}
               keyboardType={keyboardType}
               secureTextEntry={secureTextEntry}
               returnKeyType={returnKeyType}
               value={this.props.value}
               ref="textInput"
               type={'money'}
               options={{
                   suffixUnit: ' €',
                   unit: '',
               }}
>

</TextInputMask>

2017-06-16 18_35_21

`datetime` mask allows invalid data

Having type="datetime" and format as "MM/YY" allows to enter any numeric characters, e.g 99/00 or 13/22 which are not valid month numbers I assume.

CPF mask

The CPF mask is valid when the area is blank.

Can't focus on TextInputMask if customTextInput is defined

I'm passing an Input from native-base as the customTextInput parameter of a TextInputMask:

<Item>
  <Label>Sobrenome</Label>
  <Input
    value={lastName}
    ref='lastNameInput'
    autoCapitalize='words'
    returnKeyType='next'
    onSubmitEditing={() => { this.refs.dateOfBirthInput.getElement().focus() }}
    onChangeText={text => this.onChangeField('lastName', text)}
  />
</Item>
<Item>
  <Label>Data de Nascimento</Label>
  <TextInputMask
    ref='dateOfBirthInput'
    type='datetime'
    returnKeyType='next'
    options={{
      format: 'DD/MM/YYYY'
    }}
    customTextInput={Input}
  />
</Item>

The code above raises a function is not defined error. If I remove the customTextInput={Input} it can focus fine. The only workaround I've found is calling this:

this.refs.dateOfBirthInput.refs['$input-text']._root.focus()

But the keyboard do not show, so it is not a proper fix.

Custom Masked Input

Hey! Wondering if you had an example of how one would use your library to do a mask for a SSN. like take 111-11-1111 and mask it as XXX-XX-1111 while retaining the underlying value of 111-11-1111? Is this possible with the library?

TextInput Focus

This component is created byTextInputreact-native component. But react-native-masked-text don't have method like focus() and other.

So I use this way, this.refs._some_ref.refs['$input-text'].focus() But I think that is not cool.

How can i mask a decimal value?

I'm trying to mask a decimal value, but i can't did this.

Something like a repetition pattern would work too.

ex: [0-9]-[0-9]*

Any idea?

Tks

Nagative values

It would be interesting to have an option to input negative values ​​in case of numerical values.

Phone number region

Is it possible set phone region in tour module?
For example: +7 (999) 999 99-99
'+7' is region

<TextInputMask 
	style={styles.input}
	type={'custom'}
	options={{
		mask: '+7 (999) 999-99-99',
	}} 
	placeholder="Телефон"
	placeholderTextColor="#DBCCC0"
	selectionColor="#CF0821"
	underlineColorAndroid="transparent"
	keyboardType="numeric"
	value={this.state.phoneValue}
	onChangeText={(text) => {
		this.phone = text;	
		this.setState({phoneValue: text});					
		this.setState({phone: false});					
	}}
/>

But, when i change input, i see this
image

Type: money, shows 0

Is it possible to not show 0(zero) on type 'money', after deleting the value?

Add raw value to onTextChange

Hello!
Masking usually used for UX. For data flows inside the app better raw input. It would be cool if masked text input pass in onTextChange two values: masked and raw.

How to apply custom mask for cel-phone type?

I want to do something like this:

<TextInputMask
            type={'cel-phone'}
            placeholder="Enter your mobile number"
            placeholderTextColor="#cccbd0"
            style={styles.numberInput}
            options={{
              mask: '(999) 999-9999'
            }}
/>

But it doesn't work that way, so I did this instead:

<TextInputMask
            type={'custom'}
            placeholder="Enter your mobile number"
            placeholderTextColor="#cccbd0"
            style={styles.numberInput}
            options={{
              mask: '(999) 999-9999'
            }}
/>

Seems to be ok but it opens alphabetical keyboard. Is it possible to use type="cel-phone" with a custom mask?

Space between unit and amount

I'm using the money mask on text input and notice there's an extra space between my "$" and amount. For example : "$ 8.25" instead of "$8.25".

Is this space intentional and or any way to remove it?

es2015 preset on .babelrc

Hi,

I recently installed this package on an app that I'm developing and was working fine, but today, when I did a npm update, the following error started showing:

Couldn't find preset "es2015" relative to directory

After research, i figured out that the problem is the "es2015" preset on .babelrc file. After I removed it, the app worked fine. I tested the TextInputMask and it worked fine without the "es2015" preset.

So, I think that it can be removed from the repo.

Use validation without mask

It would be interesting to add the library the possibility of not applying mask but use the validation, for example for emails

Date fns instead of moment js

I installed this lib in an instant because it is something I need but I really do not like moment js. I believe date fns is a much lighter faster lib. I am looking at other libs now that this is using momentjs.

defaultValue prop not supported?

Does v1.6.2 not support defaultValue prop for TextInput component? If not, what's the best approach to setting a persisted value without having to keep the state in sync?
Looks like this was removed in v1.3.4 in favor of a placeholder prop.

undefined is not a function (evaluating 'babelHelpers.typeof(exports)')

Hi

I'm getting this error after installing react-native-masked-text. Seems to be originating from the included .babelrc. If I remove the es2015 preset, it works.

Running on React Native 0.39.2.

This is my .babelrc

{
  "passPerPreset": true,
  "sourceMaps": "inline",
  "presets": [
    "react-native"
  ],
  "plugins": [
    "./plugins/babelRelayPlugin",
    "transform-flow-strip-types",
    "transform-class-properties"
  ]
}

Would it be possible to either remove th es2015 preset or distribute a transpiled version to npm?

image

[Question] Getting raw and masked input values

Hello, from the README, it is not particularly clear to me, the proper way to get values from the inputs e.g.

import React, {Component} from 'react';

// import the component
import {TextInputMask} from 'react-native-masked-text';

export default class MyComponent extends Component {
    constructor(props) {
        super(props);
    }

    isValid() {
        // isValid method returns if the inputed value is valid.
        // Ex: if you input 40/02/1990 30:20:20, it will return false
        //     because in this case, the day and the hour is invalid.
        let valid = this.refs['myDateText'].isValid();

        // get converted value. Using type=datetime, it returns the moment object.
        // If it's using type=money, it returns a Number object.
        let rawValue = this.refs['myDateText'].getRawValue();
    }

    render() {
        // the type is required but options is required only for some specific types.
        return (
            <TextInputMask 
                ref={'myDateText'}
                type={'datetime'}
                options={{
                    format: 'DD-MM-YYYY HH:mm:ss'
                }} />
        );
    }
}

From the above usage example, how and when is the method isValid() called? And how should onChangeText be used? Thanks

maxlength not working

maxlength not working? Can you help me for this problem.
thanks for awesome library, this is very helpful

Open source licence missing

There is no licence defined in the package.json or in the repository. This should be done to ensure the library is available as open source.

Thanks for the library!

Value resets when parent's state changes

If you have a the a TextInputMask inside a component and this component re-renders due to a state change, the TextInputMask resets its value.

The same doesn't happen with TextInput.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.