javascript for Yanhui's validation functions