Proper query building and sanitization is the only reasonable solution.
(the most annoying part is that I'd change it if I could because it has no value to me and is just a pain, but that my government doesn't allow it... :-/)
I'm never quite sure what to do on offline forms that have boxes for characters that run out, I normally just continue writing past the boxes, but at least one official government documentation has been addressed to me just missing the second one.
And a few things seem to handle having multiple middle names (and thus middle initials) poorly, ignoring the length.
This lasted about 5 years before it was reversed. I met someone who had this in her last name and thought she was yanking my chain.
I'm so sorry my country did this.
Here is something in French that mentions the law, I couldn't easily find the original law online:
https://www.senat.fr/questions/base/2011/qSEQ110418181.html
Now that I think about it, it's entirely possible that it caused some issues with SQL.