handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
24 lines (23 loc) • 671 B
JavaScript
import { isNumeric } from "../../helpers/number.mjs";
export const VALIDATOR_TYPE = 'numeric';
/**
* The Numeric cell validator.
*
* @private
* @param {*} value Value of edited cell.
* @param {Function} callback Callback called with validation result.
*/
export function numericValidator(value, callback) {
let valueToValidate = value;
if (valueToValidate === null || valueToValidate === undefined) {
valueToValidate = '';
}
if (this.allowEmpty && valueToValidate === '') {
callback(true);
} else if (valueToValidate === '') {
callback(false);
} else {
callback(isNumeric(value));
}
}
numericValidator.VALIDATOR_TYPE = VALIDATOR_TYPE;