I'll havea go at helping.
A lot of the process is just validating inputs and escaping characters
disallow special characters in inputs, the key characters being < and >
you could escape certain special characters on submission < becomes & lt ; > & gt ;
add a csp header so scripts from other origins cant just be injected
avoid inline javascript all of this can be hijacked
the same techniques should be applied on the backend
frameworks like angular and react come with some built in functionality to help address this
Thats all there really is to this task, regular expressions and maintaining whitelists/blacklists of disallowed content.
Appreciating your only trying to solve the frontend, but it is most important to do this at the api and database level as anyone can just scrape the request and bypass any frontend form validations no matter how hard you go at it.
prehaps you're really trying to solve the issue with the site being blocked? in that case it'll be helpful to see the error reason?