JoeGeeky
JoeGeeky

Reputation: 3796

Testing for presence of UTF-8 character in JQuery string failing

I'm trying to create a JQuery function that will test a string for the presence of a specific UTF-8 Character.

In this case the character is U+00AD (Soft Hyphen).

Here is one variation of the function I've tried, but just can't find a working solution.

var index = obj.value.indexOf($('­').text());
var isMatch = index >= 0;

if (isMatch) {
    //Do match work
}

Can anyone suggest a fix; or something else; I can use to accomplish this?

Upvotes: 0

Views: 108

Answers (1)

SLaks
SLaks

Reputation: 888303

That's a unicode character; UTF8 is just an encoding.

You can put the character directly in the string. However, since it's invisible, it would be more readable to use a Javascript escape sequence: "\u00AD"

Upvotes: 1

Related Questions