In all real time application we need to use validation so that proper data is been entered by user. Lets see how we can do it in Node.js:
Node.js provides ‘validator‘ library to do validation. To install validator do following:
npm install validator
This package covers most of the string sanitization and validation.
For example, isEmail(), isURL(), isIP(), etc.
On server side you need to check validation as shown below:
var validator = require‘validator‘;
validator; isEmail
On client side do following:
Add <script type=”text/javascript” src=”validator.min.js”></script>
validator.isEmail(‘foo@bar.com‘); // return true
ProsperaSoft offers Node.js development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Node.js experts and consultants.