How to use the formsy-react.addValidationRule function in formsy-react

To help you get started, we’ve selected a few formsy-react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Giveth / giveth-dapp / src / lib / validators.js View on Github external
// Greater than number
addValidationRule('greaterThan', (formValues, inputValue, value) => parseFloat(inputValue) > value);

// Less than number
addValidationRule('lessThan', (formValues, inputValue, value) =>
  inputValue ? parseFloat(inputValue) < value : true,
);

// Less or equal to number
addValidationRule('lessOrEqualTo', (formValues, inputValue, value) =>
  inputValue ? parseFloat(inputValue) <= value : true,
);

// Greater than number
addValidationRule(
  'greaterEqualTo',
  (formValues, inputValue, value) => parseFloat(inputValue) >= value,
);

addValidationRule('isMoment', (formValues, inputValue) => moment.isMoment(inputValue));

// Checks if input is a valid Ether address
// TODO: Does not support ENS! (It's hard, ENS returns promises)
addValidationRule(
  'isEtherAddress',
  (formValues, inputValue, _value) => !inputValue || Web3.utils.isAddress(inputValue),
);

addValidationRule(
  'isNumber',
  (formValues, inputValue, _value) => !inputValue || /^\d+$/.test(inputValue),
github Giveth / giveth-dapp / src / lib / validators.js View on Github external
import { addValidationRule } from 'formsy-react';
import moment from 'moment';
import Web3 from 'web3';

// Formsy validations

// Greater than number
addValidationRule('greaterThan', (formValues, inputValue, value) => parseFloat(inputValue) > value);

// Less than number
addValidationRule('lessThan', (formValues, inputValue, value) =>
  inputValue ? parseFloat(inputValue) < value : true,
);

// Less or equal to number
addValidationRule('lessOrEqualTo', (formValues, inputValue, value) =>
  inputValue ? parseFloat(inputValue) <= value : true,
);

// Greater than number
addValidationRule(
  'greaterEqualTo',
  (formValues, inputValue, value) => parseFloat(inputValue) >= value,
);

addValidationRule('isMoment', (formValues, inputValue) => moment.isMoment(inputValue));

// Checks if input is a valid Ether address
// TODO: Does not support ENS! (It's hard, ENS returns promises)
addValidationRule(
  'isEtherAddress',
  (formValues, inputValue, _value) => !inputValue || Web3.utils.isAddress(inputValue),
github Automattic / jetpack / _inc / client / components / form / index.jsx View on Github external
val;

		while ( len ) {
			val = parseInt( ccNum.charAt( --len ), 10 );
			bit ^= 1;
			sum += bit ? arr[ val ] : val;
		}

		return sum && sum % 10 === 0;
	};
} )( [ 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 ] );

// To find out more about validators, see:
// https://github.com/christianalfoni/formsy-react/blob/master/API.md#validators

Formsy.addValidationRule( 'isCC', function( values, value ) {
	if ( value === undefined || value === null ) {
		return false;
	}

	// strip spaces
	value = value.replace( /\s/g, '' );

	return value.length > 12 && luhnChk( value );
} );

Formsy.addValidationRule( 'isArray', function( values, value ) {
	return isArray( value );
} );

Form.ActionBar = ActionBar;
Form.Section = Section;

formsy-react

A form input builder and validator for React

MIT
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis