How to validate password using express-validator npm
<p>I am writing rest API using node , express web module. For validation I am using <strong>express-validator</strong> npm. I want to apply some validation rules on password field.</p>

<p>How can I achieve it using express-validator?</p>

<p>What validation rules I want to apply for password as:</p>

<ol>
<li>min 8 char long.</li>
<li>At least one uppercase.</li>
<li>At least one lower case.</li>
<li>At least one special character.</li>
</ol>

<p>I read in <a href="https://aomm1ez.blogspot.in/2013/03/nodejs-validator.html" rel="noreferrer">this</a> link that there is a function available called <strong>regex()</strong> . So I tried it but not working at all.</p>

<p>My approach:</p>

<pre><code>req.check("password", "Password should be combination of one uppercase , one lower case, one special char, one digit and min 8 , max 20 char long").regex("/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/", "i");
</code></pre>

<p><strong>Error</strong> </p>

<p><a href="https://i.stack.imgur.com/DyiAM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DyiAM.png" alt="enter image description here"></a></p>

<p>In <strong><a href="https://github.com/ctavan/express-validator" rel="noreferrer">express-js</a></strong>  they have listed all the methods but did not find method / trick which solve my problem.</p>