Use replace rather than trim

Browser support is IE9+, but this would go towards making it more lenient to older browsers that don't support trim