There are other posts here re: Apex matcher functions and replacing characters in a string. I simply need to know if a given string contains any non-gsm chars. GSM refers to a standardized set of characters used for mobile texting. I don't need to know which char or index it is.
I found a regex for gsm that seems solid:
GSM_CHARACTERS_REGEX = "^[A-Za-z0-9 \\r\\n@£$¥èéùìòÇØøÅå\u0394_\u03A6\u0393\u039B\u03A9\u03A0\u03A8\u03A3\u0398\u039EÆæßÉ!\"#$%&'()*+,\\-./:;<=>?¡ÄÖÑܧ¿äöñüà^{}\\\\\\[~\\]|\u20AC]*$"
I'm thinking there must be something quicker than checking every char in my string -- something like the some
property from Javascript?
Any ideas?
I would use a keyup event to test the latest char entered, but it's possible that users will paste in a string, or use a template that inputs the full string all at once.
I can handle this check either in Javascript on the client, or in Apex. Currently thinking that I'll create a const array of all the gsm chars, then immediately before sending to Apex, I'll use javascript string.split("")
to create an array of all the letters, then create a set from that array, then loop through the set, checking to see if const gsm includes the char.
Global System for Mobile Communications
, but it is not clear based on what I know of it how that would constrain your character set.