Added validate function to js file