├── .eslintignore ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── Readme.md ├── examples └── example.gif ├── package-lock.json ├── package.json ├── src ├── Form.js ├── Input.js ├── TextValidator.jsx ├── ValidationRules.jsx ├── index.js └── utils.js └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/** 2 | **/__test__/** 3 | build/** -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser" : "babel-eslint", 3 | "plugins": [ 4 | "import" 5 | ], 6 | "extends" : ["airbnb"], 7 | "rules": { 8 | // Soft some rules. 9 | "camelcase": "off", 10 | "class-methods-use-this": "off", 11 | "default-case": 0, // Required default case is nonsense. 12 | "indent": [2, 4, { 'SwitchCase': 1, 'VariableDeclarator': 1 }], 13 | "linebreak-style": "off", 14 | "max-len": "off", 15 | "new-cap": [2, {"capIsNew": false, "newIsCap": true}], // For Record() etc. 16 | "newline-per-chained-call": 0, 17 | "no-cond-assign": "off", 18 | "no-floating-decimal": 0, // .5 is just fine. 19 | "no-nested-ternary": 0, // It's nice for JSX. 20 | "no-param-reassign": 0, // We love param reassignment. Naming is hard. 21 | "no-plusplus": 0, 22 | "no-prototype-builtins": 0, 23 | "no-shadow": 0, // Shadowing is a nice language feature. Naming is hard. 24 | "react/no-string-refs": 0, 25 | "no-underscore-dangle": "off", 26 | // eslint-plugin-import 27 | "import/no-unresolved": [2, {"commonjs": true}], 28 | "import/no-extraneous-dependencies": 0, 29 | "import/named": 2, 30 | "import/default": 2, 31 | "import/namespace": 2, 32 | "import/export": 2, 33 | "func-names": ["error", "as-needed"], 34 | // Overide Stateless 35 | "react/prefer-stateless-function": 0, 36 | "react/jsx-indent": [2, 4], 37 | "react/jsx-indent-props": [2, 4], 38 | "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], 39 | "react/no-unused-prop-types": 0, 40 | "react/no-array-index-key": 0, 41 | "react/forbid-prop-types": 0, 42 | "react/require-default-props": 0, 43 | "jsx-a11y/anchor-has-content": 0, 44 | }, 45 | "globals": { 46 | "after": false, 47 | "afterEach": false, 48 | "before": false, 49 | "beforeEach": false, 50 | "describe": false, 51 | "it": false, 52 | "require": false, 53 | "window": true, 54 | "localStorage": true, 55 | "document": true, 56 | "navigator": true, 57 | "location": true, 58 | "XMLHttpRequest": true, 59 | "XDomainRequest": true, 60 | "Blob": true, 61 | }, 62 | "settings": { 63 | "import/ignore": [ 64 | "node_modules", 65 | "\\.json$" 66 | ], 67 | "import/parser": "babel-eslint", 68 | "import/resolve": { 69 | "extensions": [ 70 | ".js", 71 | ".jsx", 72 | ".json" 73 | ] 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib/* 2 | etc/* 3 | node_modules 4 | .DS_Store 5 | build/* 6 | npm-debug.log 7 | config.jsx 8 | !config.jsx.dist 9 | .idea 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | examples/* 2 | src/* 3 | etc/* 4 | node_modules 5 | .DS_Store 6 | build/* 7 | npm-debug.log 8 | config.jsx 9 | !config.jsx.dist 10 | .idea 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - 6 6 | rvm: 7 | - 2.2.3 8 | script: "npm run lint" 9 | cache: 10 | directories: 11 | - node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 NewOldMax 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ## Validation component for react-native forms 2 | 3 | [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT) 4 | [![npm version](https://badge.fury.io/js/react-native-validator-form.svg)](https://badge.fury.io/js/react-native-validator-form) 5 | [![Build Status](https://travis-ci.org/NewOldMax/react-native-validator-form.svg?branch=master)](https://travis-ci.org/NewOldMax/react-native-validator-form) 6 | 7 | Simple form validation component for React-Native inspired by [formsy-react](https://github.com/christianalfoni/formsy-react). 8 | Web version: [react-material-ui-form-validator](https://github.com/NewOldMax/react-material-ui-form-validator) 9 | 10 | Unfortunately I don't have Mac, so this library is tested only on Android. 11 | 12 | Supported types: 13 | + TextInput 14 | 15 | Default validation rules: 16 | + matchRegexp 17 | + isEmail 18 | + isEmpty 19 | + required 20 | + trim 21 | + isNumber 22 | + isFloat 23 | + isPositive 24 | + minNumber 25 | + maxNumber 26 | + minFloat 27 | + maxFloat 28 | + minStringLength 29 | + maxStringLength 30 | + isString 31 | 32 | Some rules can accept extra parameter, example: 33 | ````javascript 34 | 38 | ```` 39 | 40 | ### Example 41 | 42 | 43 | 44 | ### Usage 45 | 46 | ````javascript 47 | 48 | import React from 'react'; 49 | import { Button } from 'react-native'; 50 | import { Form, TextValidator } from 'react-native-validator-form'; 51 | 52 | class MyForm extends React.Component { 53 | state = { 54 | email: '', 55 | } 56 | 57 | handleChange = (email) => { 58 | this.setState({ email }); 59 | } 60 | 61 | submit = () => { 62 | // your submit logic 63 | } 64 | 65 | handleSubmit = () => { 66 | this.refs.form.submit(); 67 | } 68 | 69 | render() { 70 | const { email } = this.state; 71 | return ( 72 |
76 | 87 |