Skip to content

Commit eac98d0

Browse files
committed
Improved Code, Extended InputText, Improved Example, Update README.md, Added screenshots
1 parent f4dd9fe commit eac98d0

File tree

9 files changed

+310
-312
lines changed

9 files changed

+310
-312
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/**
2+
Example/package-lock.json

Example/App.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export default class App extends Component {
88
super(props);
99
this.state = {
1010
value: "Example of string",
11+
valueRequired: "",
12+
valueNumber: 1,
1113
}
1214
}
1315

@@ -18,10 +20,30 @@ export default class App extends Component {
1820
<TextInput
1921
value={this.state.value}
2022
style={styles.input}
21-
type={"email"}
2223
onChangeText={(text) => {this.setState({value: text})}}>
2324
<Text>Default</Text>
2425
</TextInput>
26+
<TextInput
27+
value={this.state.valueRequired}
28+
required={true}
29+
style={styles.input}
30+
onChangeText={(text) => {this.setState({valueRequired: text})}}>
31+
<Text>Required</Text>
32+
</TextInput>
33+
<TextInput
34+
value={this.state.value}
35+
style={styles.input}
36+
type={"email"}
37+
onChangeText={(text) => {this.setState({value: text})}}>
38+
<Text>Email</Text>
39+
</TextInput>
40+
<TextInput
41+
value={this.state.valueNumber}
42+
style={styles.input}
43+
type={"numeric"}
44+
onChangeText={(text) => {this.setState({valueNumber: text})}}>
45+
<Text>Number</Text>
46+
</TextInput>
2547
</ScrollView>
2648
);
2749
}

README.md

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,147 @@
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+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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 | |

screenshots/example.png

-24.6 KB
Loading

screenshots/example_2.png

-24.4 KB
Binary file not shown.

screenshots/example_app.png

-94.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)