Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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),
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),
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;