@quantlab/handsontable
Version:
Spreadsheet-like data grid editor that provides copy/paste functionality compatible with Excel/Google Docs
23 lines (20 loc) • 490 B
JavaScript
/**
* Numeric cell validator
*
* @private
* @validator NumericValidator
* @param {*} value - Value of edited cell
* @param {*} callback - Callback called with validation result
*/
export default function numericValidator(value, callback) {
if (value == null) {
value = '';
}
if (this.allowEmpty && value === '') {
callback(true);
} else if (value === '') {
callback(false);
} else {
callback(/^-?\d*(\.|,)?\d*$/.test(value));
}
};