문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top