Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- let errors = [];
- function ValidationContract(){
- errors = [];
- }
- ValidationContract.prototype.isRequired = (value, message) => {
- if(!value || value.length <= 0)
- erros.push({ message:message});
- }
- ValidationContract.prototype.hasMinLen = (value, min, message) => {
- if(!value || value.length < min)
- errors.push({ message: message});
- }
- ValidationContract.prototype.hasMaxLen = (value, max, message) => {
- if(!value || value.length > max)
- errors.push({ message: message});
- }
- ValidationContract.prototype.hasFixedLen = (value, len, message) => {
- if(value.length != len)
- errors.push({ message: message});
- }
- ValidationContract.prototype.isEmail = (value, message) => {
- const reg = new RegExp(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
- if(!reg.test(value))
- errors.push({ message: message});
- }
- ValidationContract.prototype.errors = () => {
- return errors;
- }
- ValidationContract.prototype.clear = () => {
- errors = [];
- }
- ValidationContract.prototype.isValid = () => {
- return errors.length == 0;
- }
- module.exports = ValidationContract;
Advertisement
Add Comment
Please, Sign In to add comment