No Spaces Input Validation

Anyone know how I'd prevent spaces being entered on a text input field, or format the result to remove any when being inserted into a database

Try using regex:

str.replace(/\s/g, '')

that's worked, thank you