-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b3e05d
commit 47f6c18
Showing
6 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -557,7 +557,7 @@ class Validator { | |
} | ||
} | ||
|
||
return message.replace('_', ' '); | ||
return message.replace(/_/g, ' '); | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const assert = require('assert'); | ||
|
||
const should = require('should'); | ||
|
||
const Validator = require('../index'); | ||
|
||
Validator.messages({ | ||
even: 'The value of the field must be an even number.', | ||
status: 'Invalid status.' | ||
}); | ||
|
||
Validator.messages({ | ||
even: 'Even number bharo.', | ||
status: 'Galat Status.' | ||
}, 'pb'); | ||
|
||
|
||
|
||
Validator.customMessages({ | ||
'status.required': 'Status khali nahi hona chahiye.' | ||
}, 'hi'); | ||
|
||
|
||
Validator.extend('even', async function (field, value) { | ||
|
||
if ((parseInt(value) % 2) == 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
|
||
}); | ||
|
||
Validator.extend('status', async function (field, value, args) { | ||
|
||
if (args.indexOf(value) >= 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
|
||
}); | ||
|
||
let r = {}; | ||
|
||
|
||
|
||
// describe('Custom Messages', function () { | ||
|
||
// it('should return nested field message', async () => { | ||
|
||
// let v = new Validator( | ||
// { org: { name: "" } }, | ||
// { org: 'required|object', 'org.name': 'required|string' }, | ||
// { 'org.name': 'The compaany name filed is required' } | ||
// ); | ||
|
||
// let matched = await v.check(); | ||
|
||
// //throw v.errors; | ||
|
||
// // assert.equal(matched, true); | ||
|
||
// }); | ||
|
||
|
||
// }); |