Attach An Event Handler To Add To Cart Button on a Shopify page

Our Shopify store doesn’t have a way to restrict the text characters that are entered in the gift message field so customers do not include emojis. We checked with the Bold App support team and they don’t have a way to prohibit emojis in the message box. So we decided to develop a custom solution to do it. Here is the product page.

I am thinking of attaching an event handler that gets called when Add to Cart button is clicked that strips the emojis if any in the gift message before the form is submitted. I’ve not been able to find any post here in the community that already discussed something similar so I request someone to share some ideas for me to start with after having a look at the product page. I’m trying to implement the solution found on Stackoverflow in my product page.

How to detect emoji using javascript