@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`
33 lines (32 loc) • 1.35 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.email = exports.Email = void 0;
const messages_1 = __importDefault(require("./messages"));
const ValidationRule_1 = __importDefault(require("./ValidationRule"));
const regex = /^([\w-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
class Email extends ValidationRule_1.default {
static get regex() {
return regex;
}
get errorMessage() {
return this.lang(messages_1.default.email);
}
validate() {
this.isValid = regex.test(this.value);
return this;
}
}
exports.Email = Email;
exports.email = new Email();
exports.email.arrayAsSingle = function () {
throw new Error("`email` rule object is shared among inputs. If you want to invoke `arrayAsSingle`, use `new Email()` instead.");
};
exports.email.setMessageFunc = function () {
throw new Error("`email` rule object is shared among inputs. If you want to set message, use `new Email()` instead.");
};
exports.email.setPriority = function () {
throw new Error("`email` rule object is shared among inputs. If you want to set priority, use `new Email()` instead.");
};