How do i write a RegExp to validate SMS Text is only keyboard character (abc, ABC, 123, ~!@#$%^&*()`[]{}|;':',./<>?)
Thanks...
The default GSM character set is defined in GSM 03.38. Assuming you're looking at decoded text, not the 7bit packed format that is really used, a regex like the following should limit you to the allowable characters
"@£$¥èéùìòÇ\fØø\nÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./[0-9]:;<=>\?¡[A-Z]ÄÖÑܧ¿[a-z]äöñüà\^\{\}\[~\]\|€"
Note though that it is possible to sent unicode UCS-2 messages, at which point the handset receiving the message has to have suitable glyphs for presentation to the user, the unicode itself is not a limiting factor.
I propose to do it manually.
You just have to take care of some exceptions like the [
]
(need escaping) the backquote and the quote depending on the language you are writing with (since it coud end the string of the pattern)
^[a-zA-Z0-9~!@#$%^&*()`\[\]{};':,./<>?| ]*$
Maybe it would require a little tuning. I'm pretty sure that - and _ are accepted in SMS texts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With