Added validate function in javascript.