diff --git a/README.md b/README.md index 108c2017..df821f79 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ export default class MyComponent extends Component { render() { // the type is required but options is required only for some specific types. return ( - *cpf*: use the mask `999.999.999-99` and `numeric` keyboard.
*cnpj*: use the mask `99.999.999/9999-99` and `numeric` keyboard.
@@ -63,6 +63,44 @@ export default class MyComponent extends Component { *datetime*: use datetime mask with moment format (default DD/MM/YYYY HH:mm:ss). It accepts options (see later in this doc).
*custom*: use your custom mask (see the options props later in this doc).
+ +**onChangeText** + +Invoked after new value applied to mask. +```jsx +/** + * @param {String} text the text AFTER mask is applied. +*/ +onChangeText(text) { + // ... +} + + +``` + + +**checkText** + +Allow you to check and prevent value to be inputed. + +```jsx +/** + * @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'; +} + + +``` + + **TextInput Props**
You can use the native props of TextInput, with this in mind: @@ -166,7 +204,7 @@ export default class MyComponent extends Component { // the type is required but options is required only for some specific types. // the sample below will output 4567 **** **** 1234 return ( - = values.length) { @@ -216,10 +214,10 @@ VMasker.toNumber = function(value) { return value.toString().replace(/(?!^-)[^0-9]/g, ""); }; - + VMasker.toAlphaNumeric = function(value) { return value.toString().replace(/[^a-z0-9 ]+/i, ""); }; return VMasker; -})); \ No newline at end of file +})); diff --git a/lib/text-input-mask.js b/lib/text-input-mask.js index cffa3bac..d092fb65 100644 --- a/lib/text-input-mask.js +++ b/lib/text-input-mask.js @@ -18,6 +18,11 @@ export default class TextInputMask extends BaseTextComponent { _onChangeText(text) { let self = this; + + if(!this._checkText(text)) { + return; + } + self.updateValue(text) .then(maskedText => { if(self.props.onChangeText) { @@ -26,6 +31,14 @@ export default class TextInputMask extends BaseTextComponent { }); } + _checkText(text) { + if(this.props.checkText) { + return this.props.checkText(this.state.value, text); + } + + return true; + } + render() { return (