Use a beefier regex instead of filter_var. Probably doesn't fix the JS issues, though.