A money / currency validator for checkit
npm install --save checkit-money
import money from 'checkit-money';
import Checkit from 'checkit';
Checkit.Validator.prototype.money = money;
const checkit = new Checkit({
foo: ['money']
});
const test = {
foo: 23.45
};
checkit.run(test).then(() => {
console.log('validated');
}).catch(Checkit.Error, function(err) {
console.log(err.toJSON());
});
By default a number with an optional 2 decimal palces is accepted. Strings and numbers are valid:
34
4.56
0.34
'65.34'
To ensure that the vaule always has a decimal value:
const checkit = new Checkit({
foo: ['money:true']
});
To allow the value to have an optional preceding symbol. EG '£34.56'
const checkit = new Checkit({
foo: ['money:false:true']
});