I haven't been able to successfully escape Apostrophe on iPhone. After some research, it seems the Smart Punctation feature is causing some issues here. I've tried everything I can find and nothing has worked.
A user is entering text into a field and I verify if this text is correct. Here is my jQuery code. The valid Text is EMPORER'S EYE or Emporer's Eye, but neither ever comes up as valid on iPhone.
$("#actionButton").click(function() {
var seats = $("#number2").val();
var apostrophe = '\u0027';
var error = null;
if ((seats === "EMPORER\'S EYE") || (seats === 'Emporer\'s Eye')) {
$("#message").fadeIn();
$("#draggable").fadeOut();
$("#draggable2").fadeOut();
} else {
$("#messageWrong").fadeIn().delay(2500).fadeOut();
$("#draggable").fadeOut().delay(2500).fadeIn();
$("#draggable2").fadeOut().delay(2500).fadeIn();
}
// If you really need setflag:
var setflag = error != null;
});
Here is a codepen I have of the entire function and process I'm trying to put together. https://codepen.io/MaxwellR/pen/BaYGPJL
In order to make user experience less frustrating, I would skip on checking the special characters, as this is a slippery slope.
You can convert both input and expected value to certain format that allows some degree of liberty in how people spell things. Consider this example:
const sanitizeString = string => string
.trim() // remove surrounding whitespace
.toLowerCase() // ignore the case
.replaceAll(/[^\p{L}\s]/gu, '') // cut out all special characters
.replaceAll(/\s+/g, ' '); // convert any consecutive whitespace to a space
This can be a good balance between being correct and having some freedom to spell things differently.
const string = 'Emporer\'s Eye';
const sanitizedString = sanitizeString(string);
// sanitizedString is now "emporers eye"
In your case, you could have a single value inside the condition and it would work:
if (sanitizedString(seats) === sanitizedString('Emporer\'s Eye')) {
// some magic
}