wormhit wormhit - 5 days ago 4
PHP Question

Validate broken copy paste user input

I'm looking for a php function or library or suggestions that can validate broken form input value when customer copy & pastes broken utf8 string.

Scenario:


  1. Customer is asked to enter street name in

  2. He opens third party broken page where he is storing address

  3. Copies broken utf8 string (see examples)

  4. Paste this string in input field and clicks Submit



So on server side, I'm receiving "correct" valid utf8 value.

Is there a way to catch this some how so I could catch it and show error message?

Test examples:


  • "At’s ‘em"

  • "Bo�kowski"


Answer

Because there is no generic way of figuring out if value is wrong, I ended up matching regexp [A-Za-z0-9\ -.,] and showing warning message to user if not matched.

(suggested by @soheyl)