Simple JS code for validating in browser and nodejs