Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using checkit module in nodejs

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 520
    Comment on it

    Checkit allows you to validate full javascript object, defining custom rules and message, I supports both asynchronous and synchronous validations. The validations by checkit works for both on browser and server.

     

    Sample code:

    1. Async:

    var checkit = new Checkit({
    
      firstName: 'required',
    
      email: '[required', 'email']
    
    });
    
    var body = {
    
      firstName: 'DInesh'.
    
      email: 'dinesh.rawat@evontech.com',
    
    };
    
    
    checkit.run(body).then(function(validated) {
    
      console.log(validated);
    
    }).catch(Checkit.Error, function(err) {
    
      console.log(err.toJSON());
    
    })

     

    If the provided date is invalid, it will produce the errors in below format:
     

    {
    
    error: {
    
    fname: "fname is required."
    
    }
    
    }

     

    2: Sync:

    var checkit = new Checkit({
    
      firstName: 'required',
    
      email: ['required', 'email']
    
    });
    
    
    var body = {
    
      email: 'test@example.com',
    
      firstName: 'Dinesh',
    
    };
    
    
    var [err, validated] = checkit.validateSync(body);

    The err contains error object. Validated contains valid data if error object is null.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: