@react-input-validator/rules
Version:
The validation rule objects used by the packages: `@react-input-validator/core`, `@react-input-validator/native` and `@react-input-validator/web`
36 lines (35 loc) • 1.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.numeric = exports.Numeric = void 0;
const messages_1 = __importDefault(require("./messages"));
const ValidationRule_1 = __importDefault(require("./ValidationRule"));
const regex = /^(\+|-)?(\d+(\.\d+)?|\.\d+)$/;
class Numeric extends ValidationRule_1.default {
static get regex() {
return regex;
}
get errorMessage() {
return this.lang(messages_1.default.numeric);
}
get resultValue() {
return parseFloat(this.value);
}
validate() {
this.isValid = regex.test(this.value);
return this;
}
}
exports.Numeric = Numeric;
exports.numeric = new Numeric();
exports.numeric.arrayAsSingle = function () {
throw new Error("`numeric` rule object is shared among inputs. If you want to invoke `arrayAsSingle`, use `new Numeric()` instead.");
};
exports.numeric.setMessageFunc = function () {
throw new Error("`numeric` rule object is shared among inputs. If you want to set message, use `new Numeric()` instead.");
};
exports.numeric.setPriority = function () {
throw new Error("`numeric` rule object is shared among inputs. If you want to set priority, use `new Numeric()` instead.");
};