@42.nl/jarb-final-form
Version:
Validating forms through JaRB.
24 lines (23 loc) • 872 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.numberRegex = void 0;
exports.defaultFractionNumberRegex = defaultFractionNumberRegex;
/**
* Returns a regex that checks if the it is a valid number
* which can have fractions. Which are the numbers behind
* the decimal. So if the fractionLength is 5 you accept:
* #.#####, which means 5 numbers after the decimals.
*
* The number can be negative or positive.
*
* @param {number} fractionLength The length of the fraction which is considered valid.
* @return {regex} A regex which checks for fraction numbers.
*/
function defaultFractionNumberRegex(fractionLength) {
return new RegExp('^-?\\d+(\\.\\d{1,' + fractionLength + '})?$');
}
/**
* A regex which checks for a positive or negative number
* without fractions.
*/
exports.numberRegex = /^-?\d+$/;