Generic JavaScript validation