Yes, it is legal. A company can require searches of employees as a condition of employment; employees who do not wish to allow this have the option of quitting/resigning. The exception would be if the employee is being discriminated against or harassed due to a protected category or characteristic, such as his or her race, religion, age over 40, disability, or sex; if that is the case, the search may constitute illegal employment discrimination, and the employee may have grounds for legal action.