From 1bd618b4fd9d91d303d1c7639152194957a48b29 Mon Sep 17 00:00:00 2001 From: asif Date: Sat, 9 Aug 2025 21:41:29 +0530 Subject: [PATCH] implemented neft.validator.js --- src/validators/neft.validator.js | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/validators/neft.validator.js diff --git a/src/validators/neft.validator.js b/src/validators/neft.validator.js new file mode 100644 index 0000000..6f6dc83 --- /dev/null +++ b/src/validators/neft.validator.js @@ -0,0 +1,36 @@ +const neftValidator = async (req, res, next) => { + const { + fromAccount, + toAccount, + amount, + remitterName, + beneficiaryName, + ifscCode, + } = req.body; + + if (!isAccountNumbersValid(fromAccount, toAccount)) { + return res.status(400).json({ error: 'INVALID_ACCOUNT_NUMBER_FORMAT' }); + } + + if (amount < 1) { + return res.status(400).json({ error: 'INVALID_AMOUNT' }); + } + + if (!remitterName || !beneficiaryName) { + return res + .status(400) + .json({ error: 'REMITTER_NAME AND BENEFICIARY_NAME REQUIRED' }); + } + + if (!ifscCode || !/^[A-Z]{4}0[0-9]{6}$/.test(ifscCode)) { + return res.status(400).json({ error: 'INVALID_IFSC_CODE' }); + } + + next(); +}; + +const isAccountNumbersValid = (fromAcct, toAcct) => { + return !(!fromAcct || !toAcct || fromAcct.length != 11 || toAcct.length < 7); +}; + +module.exports = neftValidator;