Docs
API
  • vtype

    Mixed

    Validation type.

    There several built-in validation types and possible to do self.

    Built-in types: 'email', 'range', 'min', 'max', 'notnan', 'notempty'

    Some types can be used as string value, another requires additional params.

    Examples

    Email vtype

    
    },{
      vtype: 'email'
    },{
    
    Range vtype
    
    },{
      type: 'number',
      vtype: {
        before: ['notempty', 'notnan'],
        type: 'range',
        min: 20,
        max: 70
      }
    }]
    
    Min vtype
    
    },{
      type: 'number',
      vtype: {
        before: ['notempty', 'notnan'],
        type: 'min',
        param: 30
      }
    }]
    
    Max vtype
    
    },{
      name: 'age',
      label: 'Age',
      type: 'number',
      vtype: {
        before: ['notempty', 'notnan'],
        type: 'max',
        param: 70
      }
    }]
    
    NotNaN vtype
    
    },{
      type: 'string',
      vtype: 'notnan'
    }]
    

    To do self vtype it needs to use Fancy.addValid

    There are 2 approaches on checking validation: over RegExp and over function.

    Function

    
    Fancy.addValid('notnan', {
      text: 'Must be numeric',
      fn: function(value){
        return !isNaN(value);
      }
    });
    

    RegExp

    
    Fancy.addValid('email', {
      re: /^(")?(?:[^\."])(?:(?:[\.])?(?:[\w\-!#$%&'*+\/=?\^_`{|}~]))*\1@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
      text: 'Is not a valid email address'
    });
    

    Params

    To use params inside of function, it requires to define them.

    They will be avaliable inside of function over this

    
    Fancy.addValid('range', {
      before: ['notempty', 'notnan'],
      text: 'Must be between {min} and {max}',
      fn: function(value){
        return value >= this.min && value <= this.max;
      }
    });
    ...
    subTBar: [{
      type: 'number',
      vtype: {
        before: ['notempty', 'notnan'],
        type: 'range',
        min: 20,
        max: 70
      }
    
    

    To do complex validation, it requires to add property before with list of queue of vtypes.

    
    },{
      type: 'number',
      vtype: {
        before: ['notempty', 'notnan'],
        type: 'max',
        param: 70
      }
    }]
    

    Default

    
    undefined