Port JavaScript validation code