Question

I have a string that I am copying from word document and then passing it to my text area. The issue is that the string contains a character that appears to be Right quotation mark but jquery is unable to identify it.

I am using the following regex

return inputValue.match("^(?!.*(<|>)).*[a-zA-Z0-9 \’\‘\@\!\#\$\%\^\&\*\(\)\_\+\-\=\{\}\:\;\'\,\.\?\|\/\~\`\n]+$") == null ? true : false;

The unidentifiable strings here are

\’\‘

When I check same regex while debugging in firebug I get it as

return inputValue.match("^(?!.*(<|>)).*[a-zA-Z0-9 \ \ \@\!\#\$\%\^\&\*\(\)\_\+\-\=\{\}\:\;\'\,\.\?\|\/\~\`\n]+$") == null ? true : false;

Please note that the \’\‘ are now \ \ in jquery and hence its always failing.. I checked out further and the character comes out with Ascii Value of

&#8216;

and

&#8217;

Please let me know a way to change these to normal single quote i.e of Ascii value 39. or to completely remove it from the string

I know I can use a replace function to do the same, but the issue is that its not just related to single quote.. it can be any other character in future also..

So I need a foolproof solution for these illegal/Unidentifiable characters

Était-ce utile?

La solution

Try using their hex equivalent (also make your string literal with @):

return inputValue.match(@"^(?!.*(<|>)).*[a-zA-Z0-9 \u2018\u2019@!#$%^&*()_+={}:;',.?|/~`\n-]+$") == null ? true : false;
                                                   ^^^^^^^^^^^^

\u2018 is for and \u2019 is for .

ideone demo

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top