简体   繁体   中英

How can I sanitize text from a codename one textarea?

I have a text area in a form that is filled by the user. There are no constraints on the text area.

Because of the prepondernce of differnt types of mobile keyboards, I want to make sure that the text I get from the text area is sanitized. ie It should be stripped clean of any emoticons or hidden characters. It should only contain alphaumeric and punctuation characters.

What is the best way to do this in codename one? Thank you for your help.

This can be done using a regexp and there is no cleaner way. However, I believe you are approaching the problem sub-optimally.

You can detect the browser used by the user from the user agent string and based on that you can determine whether emoticons should be shown or not. Before you render the content, check whether emoticons should be shown. If not, then filter out unneeded characters. If yes, then show those emoticons.

Finally, I must mention that you must protect your database against SQL injection attempts or accidental bugs and you should make sure that XSS is not possible either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM