Example #1
0
exports['url validators'] = function(test){
    test.equals(
        fields.url().validators[0].toString(),
        forms.validators.url().toString()
    );
    var fn1 = function(){return 'one';};
    var fn2 = function(){return 'two';};
    var f = fields.url({validators: [fn1, fn2]});
    test.equals(
        f.validators[0].toString(),
        forms.validators.url().toString()
    );
    test.same(f.validators.slice(1), [fn1, fn2]);
    test.done();
};
Example #2
0
 validators.minlength(5)('form', {data:'1234'}, function(err){
     test.equals(err, 'Please enter at least 5 characters.');
     validators.minlength(5)('form', {data:'12345'}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 });
Example #3
0
 validators.email()('form', {data: '*****@*****.**'}, function(err){
     test.equals(err, undefined);
     validators.email()('form', {data: 'a←+b@f.museum'}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 });
Example #4
0
 validators.url()('form', {data: 'asdf.com'}, function(err){
     test.equals(err, 'Please enter a valid URL.');
     validators.url()('form', {data: 'http://asdf.com'}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 })
Example #5
0
 validators.max(100)('form', {data: 150}, function(err){
     test.equals(err, 'Please enter a value less than or equal to 100.');
     validators.max(100)('form', {data: 100}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 });
Example #6
0
 validators.range(10, 20)('form', {data: 50}, function(err){
     test.equals(err, 'Please enter a value between 10 and 20.');
     validators.range(10, 20)('form', {data: 15}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 });
Example #7
0
 validators.maxlength(5)('form', {data:'123456'}, function(err){
     test.equals(err, 'Please enter no more than 5 characters.');
     validators.maxlength(5)('form', {data:'12345'}, function(err){
         test.equals(err, undefined);
         test.done();
     });
 });
Example #8
0
 validators.regexp(/^\d+$/)('form', {data: '123'}, function(err){
     test.equals(err, undefined);
     var v = validators.regexp('^\\d+$', 'my message');
     v('form', {data: 'abc123'}, function(err){
         test.equals(err, 'my message');
         test.done();
     });
 });
Example #9
0
 function(callback){
     validators.rangelength(2,4)('form', {data:'1'}, function(err){
         test.equals(
             err, 'Please enter a value between 2 and 4 characters long.'
         );
         callback();
     });
 },
Example #10
0
exports['min'] = function(test){
    validators.min(100)('form', {data: 50}, function(err){
        test.equals(err, 'Please enter a value greater than or equal to 100.');
        validators.min(100)('form', {data: 100}, function(err){
            test.equals(err, undefined);
            test.done();
        });
    });
};
Example #11
0
exports.fields.money = function(opt) {
  opt = opt || {};
  opt.validators = opt.validators || [];
  opt.validators.splice(0, 0,
      forms.validators.regexp(
              /[0-9]+\.[0-9]{2}/,
              'This field must be in the format of 0.00.'));

  return fields.string(opt);
};
Example #12
0
 validators.email()('form', {data: 'asdf'}, function(err){
     test.equals(err, 'Please enter a valid email address.');
     validators.email()('form', {data: '*****@*****.**'}, function(err){
         test.equals(err, undefined);
         validators.email()('form', {data: 'a←+b@f.museum'}, function(err){
             test.equals(err, undefined);
             test.done();
         });
     });
 })
Example #13
0
exports['matchField'] = function(test){
    var v = validators.matchField('field1');
    var data = {
        fields: {
            field1: {data: 'one'},
            field2: {data: 'two'}
        }
    };
    v(data, data.fields.field2, function(err){
        test.equals(err, 'Does not match field1.');
        data.fields.field2.data = 'one';
        v(data, data.fields.field2, function(err){
            test.equals(err, undefined);
            test.done();
        });
    });
};
Example #14
0
exports.fields.integer = function(opt) {
  opt.validators = opt.validators || [];
  opt.validators.splice(0, 0,
      forms.validators.regexp(/[0-9]+/, 'This field must be numeric.'));
  return fields.number(opt);
};
Example #15
0
 function(callback){
     validators.rangelength(2,4)('form',{data:'1234'}, function(err){
         test.equals(err, undefined);
         callback();
     });
 },