all files / src/ build-in-validators.ts

42.86% Statements 3/7
100% Branches 3/3
25% Functions 1/4
42.86% Lines 3/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                              
let validateCollection = {
    'required': (value) => {
        return !(value === undefined || value === null || /^\s*$/.test(value));
    },
    'number': (value) => {
        return /^-?\d+(?:\.\d+)?$/.test(value);
    },
    'email': (value) => {
        return /^(\w+|\.+)((-\w+|\.+)|(\.+\w+))*\@\w+((\.|-)\w+)*\.\w+/.test(value);
    },
    'maxLen': (value, len) => {
        let str = String(value),
            rps_value = str.replace(/^\s+|\s+$/g, '');
        return rps_value.length <= len;
    },
    // 'eq': (orginVal, compareVal) => {
    //     return  angular.equals(orginVal, compareVal);
    // },
    // 'gt': (val1, val2) => {
    //     return val1 > val2;
    // }
};
 
 
 
export {validateCollection as validators};