Gathering detailed insights and metrics for react-native-validate-form
Gathering detailed insights and metrics for react-native-validate-form
Gathering detailed insights and metrics for react-native-validate-form
Gathering detailed insights and metrics for react-native-validate-form
react-native-form-validator
React native library to validate form fields
mainam-react-native-form-validate
react-native-form-validate-hooks
react-native-form-validate-hooks
dead-simple-react-form
A simple hook to validate forms in React and React Native, powered by mobx and validated by yup
A simple yet customizable (to some extent) form validation in React Native
npm install react-native-validate-form
Typescript
Module System
Node Version
NPM Version
70.8
Supply Chain
99.3
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (60.88%)
Objective-C (20.67%)
Python (10.98%)
Java (7.47%)
Total Downloads
7,882
Last Day
3
Last Week
39
Last Month
71
Last Year
708
MIT License
8 Stars
58 Commits
5 Forks
1 Watchers
2 Branches
2 Contributors
Updated on Mar 31, 2020
Latest Version
1.1.3
Package Id
react-native-validate-form@1.1.3
Unpacked Size
16.73 kB
Size
5.32 kB
File Count
11
NPM Version
5.6.0
Node Version
8.11.3
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
333.3%
39
Compared to previous week
Last Month
-1.4%
71
Compared to previous month
Last Year
20.2%
708
Compared to previous year
No dependencies detected.
A simple form validation for React Native
Install react-native-validate-form using NPM with:
npm install --save react-native-validate-form
1import { Form, Field } from 'react-native-validate-form';
See github documentation for more info.
1import React from 'react'; 2import { View, Text } from 'react-native'; 3import { Form, Field } from 'react-native-validate-form'; 4 5import InputField from './InputField'; 6 7const required = value => (value ? undefined : 'This is a required field.'); 8const email = value => value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,5}$/i.test(value) ? 'Please provide a valid email address.' : undefined; 9 10class MyForm extends React.Component { 11 constructor() { 12 super(); 13 14 this.state = { 15 errors: [], 16 email: '' 17 } 18 } 19 submitForm() { 20 let submitResults = this.myForm.validate(); 21 22 let errors = []; 23 24 submitResults.forEach(item => { 25 errors.push({ field: item.fieldName, error: item.error }); 26 }); 27 28 this.setState({ errors: errors }); 29 } 30 31 render() { 32 return( 33 <Form 34 ref={(ref) => this.myForm = ref} 35 validate={true} 36 submit={this.submitForm.bind(this)} 37 errors={this.state.errors} 38 > 39 <Field 40 required 41 component={InputField} 42 validations={[ required, email ]} 43 name="email" 44 value={this.state.email} 45 onChangeText={(val) => this.setState({ email: val })} 46 customStyle={{ width: 100 }} 47 /> 48 </Form> 49 ); 50 } 51}
this.myForm.validate()
.1 import React from 'react'; 2 import { TextInput, Text, View } from 'react-native'; 3 4 const InputField = ({ 5 name, // field name - required 6 customStyle, 7 onChangeText, // event 8 value, // field value 9 disabled, 10 placeholder, 11 errors, // this array prop is automatically passed down to this component from <Form /> 12 }) => { 13 return ( 14 <View> 15 <TextInput 16 value={value && value} 17 onChangeText={onChangeText ? (val) => onChangeText(val) : null} 18 placeholder={placeholder ? placeholder : ""} 19 disabled={disabled} 20 style={customStyle ? customStyle : {}} 21 /> 22 23 { errors && errors.length > 0 && errors.map((item, index) => 24 item.field === name && item.error ? 25 <Text style={{ color: 'red' }}> 26 {item.error} 27 </Text> 28 : <View /> 29 ) 30 } 31 </View> 32 ); 33 } 34 35 export default InputField;
<Field />
components, you need to explicitly pass down errors
as props so you can display the errors accordingly.errors
as props if your <Field />
component is a direct child of <Form />
.1 // ... 2 <Form 3 ref={(ref) => this.myForm = ref} 4 validate={true} 5 submit={this.submitForm.bind(this)} 6 errors={this.state.errors} // you still need to pass errors as props to Form 7 > 8 <Field 9 required 10 component={InputField} 11 validations={[ required, email ]} 12 name="email" 13 value={this.state.email} 14 onChangeText={(val) => this.setState({ email: val })} 15 customStyle={{ width: 100 }} 16 // no need to pass down errors as props if <Field /> is a direct child of <Form /> 17 /> 18 <View> 19 <Field 20 required 21 component={InputField} 22 validations={[ required, email ]} 23 name="email" 24 value={this.state.email} 25 onChangeText={(val) => this.setState({ email: val })} 26 customStyle={{ width: 100 }} 27 errors={this.state.errors} // explicitly pass down errors as props if your <Field /> is inside an element 28 /> 29 </View> 30 </Form> 31 // ...
TODO: make an example in the repo for better documentation
You can pass these props
to the Form and Field components:
1<Form 2 ref={(ref) => this.myForm = ref} 3 validate={true} 4 submit={onSubmit} 5> 6 <Field 7 required 8 component={InputField} 9 validations={[ sampleValidation() ]} 10 /> 11</Form>
Props you can pass for the <Form />
component
Name | Type | Default | Required | Description |
---|---|---|---|---|
ref | string | null | yes | reference name |
validate | boolean | false | no | set this to true to enable validation |
submit | function | () => null | no | function callback if form is valid |
failed | function | () => null | no | function callback if form is invalid |
errors | array | [] | no | array that contains all your field errors and messages |
style | object | {} | no | style object |
Props you can pass for the <Field />
component
Name | Type | Default | Required | Description |
---|---|---|---|---|
required | boolean | false | no | set this to true to require the field |
component | component / func | null | yes | input component or any component that needs validation |
validateFieldName | string | 'value' | no | name of the prop that will be validated |
validations | func / array | [] | no | function or array of functions that contains your validation |
customStyle | object | {} | no | style object |
Copyright (c) 2018 Jefferson Aux
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 1/21 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
76 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More