|
1 | | -# react-native-input-validator |
| 1 | +# React Native Input Validator |
| 2 | +### react-native-input-validator |
| 3 | + |
| 4 | +[![NPM version][npm-image]][npm-url] |
| 5 | +[![npm download][download-image]][download-url] |
| 6 | +[](http://standardjs.com/) |
| 7 | + |
| 8 | +[npm-image]: http://img.shields.io/npm/v/react-native-input-validator.svg?style=flat-square |
| 9 | +[npm-url]: http://npmjs.org/package/react-native-input-validator |
| 10 | +[download-image]: https://img.shields.io/npm/dm/react-native-input-validator.svg?style=flat-square |
| 11 | +[download-url]: https://npmjs.org/package/react-native-input-validator |
| 12 | + |
| 13 | +**Github:** https://github.com/marcocesarato/react-native-input-validator |
| 14 | + |
| 15 | +**Author:** Marco Cesarato |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +This library validates strings and number passed on TextInput component and highlight the result (valid green, invalid red). |
| 20 | + |
| 21 | + |
| 22 | +## Install |
| 23 | + |
| 24 | +### npm |
| 25 | +```shell |
| 26 | +npm install react-native-input-validator --save |
| 27 | +``` |
| 28 | + |
| 29 | +### Yarn |
| 30 | +```shell |
| 31 | +yarn add react-native-input-validator |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### Require |
| 37 | + |
| 38 | +This library have 2 componets `InputValidator` and `InputText`. |
| 39 | +The first have floating labels (placeholder) and the second one not. |
| 40 | + |
| 41 | +```javascript |
| 42 | +include {InputValidator, InputText} from 'react-native-input-validator'; |
| 43 | +``` |
| 44 | + |
| 45 | +### Placeholder floating label |
| 46 | +```javascript |
| 47 | +// Require |
| 48 | +include {InputValidator} from 'react-native-input-validator'; |
| 49 | + |
| 50 | +// Example |
| 51 | +<InputValidator |
| 52 | + ref={(r) => { |
| 53 | + this.input = r; |
| 54 | + }} |
| 55 | + value={this.state.value} |
| 56 | + style={styles.input} |
| 57 | + onChangeText={(text) => {this.setState({value: text})}}> |
| 58 | + |
| 59 | + <Text>Default</Text> |
| 60 | + |
| 61 | +</InputValidator> |
| 62 | + |
| 63 | +// Check Validation |
| 64 | +this.input.isValidated(); // Faster |
| 65 | +this.input.isValid(); |
| 66 | +``` |
| 67 | + |
| 68 | +### Only text input |
| 69 | +```javascript |
| 70 | +// Require |
| 71 | +include {InputText} from 'react-native-input-validator'; |
| 72 | + |
| 73 | +// Example |
| 74 | +<InputText |
| 75 | + ref={(r) => { |
| 76 | + this.input = r; |
| 77 | + }} |
| 78 | + value={this.state.value} |
| 79 | + style={styles.input} |
| 80 | + onChangeText={(text) => {this.setState({value: text})}}> |
| 81 | + |
| 82 | + <Text>Default</Text> |
| 83 | + |
| 84 | +</InputText> |
| 85 | + |
| 86 | +// Check Validation |
| 87 | +this.input.isValidated(); // Faster |
| 88 | +this.input.isValid(); |
| 89 | +``` |
| 90 | + |
| 91 | +## Run example |
| 92 | +Clone or download repo and after: |
| 93 | +```shell |
| 94 | +cd Example |
| 95 | +yarn install # or npm install |
| 96 | +expo start |
| 97 | +``` |
| 98 | + |
| 99 | +Open Expo Client on your device. Use it to scan the QR code printed by `expo start`. You may have to wait a minute while your project bundles and loads for the first time. |
| 100 | + |
| 101 | +## Screenshots |
| 102 | + |
| 103 | +### Example |
| 104 | +<img src="screenshots/example.png" /> |
| 105 | + |
| 106 | +## Types |
| 107 | + |
| 108 | +- email |
| 109 | +- phone |
| 110 | +- url |
| 111 | +- currency |
| 112 | +- postal-code |
| 113 | +- hex-color |
| 114 | +- identity-card |
| 115 | +- credit-card |
| 116 | +- numeric |
| 117 | +- integer | int |
| 118 | +- real | float |
| 119 | +- decimal |
| 120 | +- alpha |
| 121 | +- alphanumeric |
| 122 | + |
| 123 | +## Handlers |
| 124 | + |
| 125 | +Same of `TextInput`. |
| 126 | +Read more here: https://facebook.github.io/react-native/docs/textinput.html |
| 127 | + |
| 128 | +## Props |
| 129 | + |
| 130 | +Same of `TextInput`. |
| 131 | +Read more here: https://facebook.github.io/react-native/docs/textinput.html |
| 132 | + |
| 133 | +Property | Description | Type | Default | Note |
| 134 | +------------------|-------------|------|---------|------- |
| 135 | +type | Type of input | String | `dafault` | | |
| 136 | +symbol | Symbol for `currency` type | String | | | |
| 137 | +locale | For better validation can be useful for some type like `postal-code`, `identity-card` etc... | String | | Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']` | |
| 138 | + |
| 139 | +## Props style |
| 140 | + |
| 141 | +Property | Description | Type | Default | Note |
| 142 | +------------------|-------------|------|---------|------- |
| 143 | +style | Input style | Object | | | |
| 144 | +labelStyle | Label Style (placeholder) | Object | Only using `InputValidator` | |
| 145 | +containerStyle | Container Style | Object | Only using `InputValidator` | |
| 146 | +validStyle | Input Style when valid | Object | | |
| 147 | +invalidStyle | Input Style when invalid | Object | | |
0 commit comments