Sanitize the javascript code generated for validation.

A ton of repetitive code that can be easily eliminated is generated.