开发者

Can I highlight multiple words in an HTML textarea that fail my regular expression in Javascript?

开发者 https://www.devze.com 2023-03-26 19:29 出处:网络
Basically, here is the deal. The application I am working on, the database it uses apparently cannot accept non US-ASCII characters in HTML textareas input fields.Now, our users have had issues copyi

Basically, here is the deal.

The application I am working on, the database it uses apparently cannot accept non US-ASCII characters in HTML textareas input fields. Now, our users have had issues copying/pasting in text from PDF documents into these fields. Our research found out that certain characters, like the left and right single quotes, apostrophes and double quote characters in the PDF documents, when pasted into the textarea, somehow are transformed into different characters that are not US ASCII and as such, causes problems within our application.

So, I have a regular 开发者_如何学Cexpression that will flag non US-ASCII (non US keyboard characters). That part of my POC is working, but now, I'd like it so that when users copy/type in text, that any words that get flagged as non-US ASCII be highlighted in the textarea when user tries to save/submit that data.

Is this possible to do? I can use the select(), but that only highlights the last word that gets flagged. Any help on this would be appreciated!

Thanks!


I suggest using an enhanced textarea (the kind which uses iframes) such as tinyMCE and highlighting the offending text with regular HTML.

See other questions such as this one or this one to see how to highlight text in textareas.

0

精彩评论

暂无评论...
验证码 换一张
取 消