A simple validation library for react native

Overview

react-native-form-validator

npm version

A simple validation library for react native

Installation

Run: $ npm i react-native-validation --save

Validators:

  • matchRegexp
  • isEmail
  • isEmpty
  • required
  • isNumber
  • isFloat
  • isPositive
  • maxNumber
  • minNumber
  • maxFloat
  • minFloat
  • isString
  • minStringLength
  • maxStringLength

Example Component:

<ValidationComponent
  component={
    <RkTextInput
      rkType="bordered"
      style={{ width: "100%" }}
      placeholder="You can type a description"
      value={description}
      onChangeText={value => this.setState({ description: value })}
    />
  }
  validators={["required","maxNumber:255"]}
  errorMessages={["this field is required", "must be max 255"]}
/>

Usage

import { ValidationForm, ValidationComponent } from "react-native-validator";

constructor(props, context) {
  super(props, context);
  ValidationComponent.setDefaultErrorMessageStyle({
    color: "white",
    fontSize: 12,
  });
}

render() {   
    return (
      <ValidationForm
        style={style.container}
        ref={ref => (this.form = ref)}
        onSubmit={() => this.props.saveUserList()}
        onError={() => console.log("houston we have a problem")}
      >
        <ValidationComponent
          component={
            <RkTextInput
              rkType="bordered"
              style={{ width: "100%" }}
              placeholder="List Name"
              value={name}
              onChangeText={value => this.setState({ name: value.trim() })}
            />
          }
          validators={["required", "isEmail"]}
          errorMessages={["this field is required", "email is not valid"]}
        />
        <ValidationComponent
          component={
            <TextInput
              style={{ width: "100%" }}
              placeholder="You can type a description"
              value={description}
              onChangeText={value => this.setState({ description: value })}
            />
          }
          errorMessageStyle={{
            color: "red"
          }}
          validators={["required"]}
          errorMessages={["this field is required"]}
        />
        <RkButton rkType="primary xlarge" onPress={() => this.form.validate()}>
          Next
        </RkButton>
      </ValidationForm>
    );
}
...

You can add your own rules

// validators={["isPasswordMatch:param1:param2"]}
ValidationForm.addValidationRule('isPasswordMatch', (value, param1, param2...) => {
    if (value !== this.state.user.password) {
        return false;
    }
    return true;
});

You can set default error style

constructor(props, context) {
  super(props, context);
  ValidationComponent.setDefaultErrorMessageStyle({
    color: "white",
  });
}

API

ValidationForm

  • Props
Prop Required Type Default value Description
onSubmit true function triggered if form is valid
onError false function triggered if form is not valid
  • Methods
Name Params Return Descriptipon
validate Check form is valid
isValid bool return current validation state

ValidationComponent

  • Props
Prop Required Type Default value Description
validators true array Array of validators.
errorMessages true array Array of error messages. Must be in the same order as validation
errorMessageStyle false object Error textComponent style
component true object Input component(Must include value prop)
style false object Container style props
  • Methods
Name Params Return Descriptipon
setDefaultErrorMessageStyle styleObject Set default style for error textComponent
You might also like...
Angular like reactive forms in React.
Angular like reactive forms in React.

React Reactive Forms It's a library inspired by the Angular's Reactive Forms, which allows to create a tree of form control objects in the component c

React component for convert the valle screens-api data structure to web component based forms.
React component for convert the valle screens-api data structure to web component based forms.

valleForm React component for convert the valle screens-api data structure to web component based forms. Write valleForm tabs = { [...] } but

Project using React Router, Styled Components, useEffect, useState and context

Before run do the steps bellow install npm or yarn To run this application you can just use npm or if you want, yarn is another option. Download NPM I

Remix-validity-state is a small React form validation library that aims to embrace HTML input validation and play nicely with Remix primitives

Remix-validity-state is a small React form validation library that aims to embrace HTML input validation and play nicely with Remix primitives

Simple form validation library for React and React Native

React Cee Form Inspired by react hook form and their props name and rewritten in a simple way. It can be used for both React Native and ReactJs. Don't

Simple form validation library for React Native.

Foect Simple form validation library for React Native. Installing Npm npm i --save foect Yarn yarn add foect Quick Start import { TextInput, Text, V

A simple validation library for react native

react-native-form-validator A simple validation library for react native Installation Run: $ npm i react-native-validation --save Validators: matchReg

A simple react and react native form validator inspired by Laravel validation.

Simple React Validator is exactly as it sounds. We wanted to build a validator for react that had minimal configuration and felt natural to use. It's configuration and usage is similar to the Laravel PHP framework and make validation as easy as one line.

The most complete React Library Component for drag’n’drop files. Image and video previews. File validation. Multilanguage. Server side support.
The most complete React Library Component for drag’n’drop files. Image and video previews. File validation. Multilanguage. Server side support.

🚀 Spanish README Dropzone UI The best, most complete and easy to use, React file upload library. ⚡ Live demo and code generator : dropzone-ui.com ❤️

Simple validation mixin (HoC) for React.

react-validation-mixin Simple validation library for React. This library simply wraps your React Component, transferring it props containing the boile

Simple-as-possible React form validation
Simple-as-possible React form validation

Simple-as-possible React form validation

React hook for handling Laravel form requests and validation (for React & React Native)

React-use-form: React hook for handling form states, requests, and validation, compatible with React and React Native. ✅ Simple and intuitive API ✅ 10

📋 React Hooks for forms validation (Web + React Native)
📋 React Hooks for forms validation (Web + React Native)

Performant, flexible and extensible forms with easy to use validation. English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Рус

📋 React Hooks for forms validation (Web + React Native)
📋 React Hooks for forms validation (Web + React Native)

Performant, flexible and extensible forms with easy to use validation. English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Рус

📋 React Hooks for forms validation (Web + React Native)
📋 React Hooks for forms validation (Web + React Native)

Version 7 | Version 6 Features Built with performance and DX in mind Embraces native form validation Out of the box integration with UI libraries Smal

📋 React Hooks for forms validation (Web + React Native)
📋 React Hooks for forms validation (Web + React Native)

Version 7 | Version 6 English | 日本語 Features Built with performance, UX and DX in mind Embraces native form validation Out of the box integration with

React-Native Credit Card Animated UI with information validation
React-Native Credit Card Animated UI with information validation

rn-credit-card-ui : A Credit Card React-Native UI component, it uses react-native-flip-card to flip the UI component smoothly and creditcardutils to v

Performance oriented React Native Phone Number Input with typings and proper validation for any country
Performance oriented React Native Phone Number Input with typings and proper validation for any country

React Native Phone Number Input Performance oriented React Native Phone Number Input with typings and proper validation for any country. Made with ❤️

React Hook Form Validation example with react-hook-form 7 and Bootstrap 4

React Hook Form Validation example with react-hook-form 7 and Bootstrap 4 Project setup In the project directory, you can run: npm install # or yarn i

Comments
  • Problem with import 'haste'

    Problem with import 'haste'

    The solution is change the code:

    import { ValidationForm, ValidationComponent } from "react-native-validator";

    to

    import { ValidationForm, ValidationComponent } from "react-native-validation";

    opened by fcamargo10 0
Releases(1.0.3)
Owner
Şerafettin Aytekin
Şerafettin Aytekin
📋 React Hooks for forms validation (Web + React Native)

Version 7 | Version 6 English | 日本語 Features Built with performance, UX and DX in mind Embraces native form validation Out of the box integration with

React Hook Form 32.6k Jan 8, 2023
A simple, declarative API for creating cross-platform, native-appearing forms with React Native

React Native Forms Project status I wrote this library several (many?) years ago for a use-case at work, when React Native was still quite young, comp

Michael Helvey 87 Jul 10, 2022
Forms library for react-native

Notice tcomb-form-native is looking for maintainers. If you're interested in helping, a great way to get started would just be to start weighing-in on

Giulio Canti 3.2k Dec 17, 2022
A simple react-native component to wrap your form fields and get their values with just one single method.

react-native-form A simple react-native component to wrap your form fields and get their values without attaching listeners everywhere. Installation n

Juliano Duarte 145 Nov 11, 2022
A Formik inspired form library that uses MobX under the hood

Formix A Formik inspired form library that uses MobX under the hood and update only the changed fields. Installation Using npm: npm install @euk-labs/

Shoulders 6 Dec 29, 2021
📝 Form component for React Native.

Gifted Form Form component for React Native. Example var { GiftedForm, GiftedFormManager } = require('react-native-gifted-form'); var FormComponent =

Farid Safi 1.4k Dec 19, 2022
Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components

react-native-clean-form Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components Bi

Esben Petersen 475 Oct 30, 2022
FM Form is a module for React Native to fast generate pages with a form.

react-native-fm-form FM Form is a module for React Native to fast generate pages with a form. It works like Backbone forms. Using this module you can

Yi Wang 13 Dec 9, 2021
Generate forms with native look and feel in a breeze

React Native Form Generator Generate forms with native look and feel in a breeze Components Picker DatePicker TimePicker Input Link Separator Switch F

Michael Cereda 375 Dec 7, 2022
Build forms in React, without the tears 😭

Build forms in React, without the tears. Visit https://formik.org to get started with Formik. Organizations and projects using Formik List of organiza

Formium 31.7k Dec 31, 2022