Validate object properties in javascript