1
         text_settings_descriptions: {
    'en': { language_id: '5a3a13238481824b077b23ca', value: '' },
    'ar': { language_id: '600eca59ced1c8317d473b54', value: '' }
  }

this is my address array

 app.post(
  '/addresses',
  check('text_settings_descriptions.*.value'),
 
  (req, res) => {
    // Handle the request
  },
);

And I am using this validation it validates both language's value. But I want it validates only 'en' language value

1 Answer 1

1

If you want to make sure that the value inside en is not empty, you can use the following:

const {check, validationResult} = require('express-validator');

app.post(
    '/addresses',
    check('text_settings_descriptions.en.value').notEmpty(),
    (req, res) => {
        const errors = validationResult(req);
        console.log(errors);
        // ... handle errors and request
    },
);

With above code if the value was an empty value, the follwoing will be logged to the console:

 {
  formatter: [Function: formatter],
  errors: [
    {
      value: '',
      msg: 'Invalid value',
      param: 'text_settings_descriptions.en.value',
      location: 'body'
    }
  ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank u for the comment but it not working
I've updated my code, please check and don't forget to accept the answer by clicking the checkmark on the left, if this answer solved your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.