Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegExp Validate SMS Text

How do i write a RegExp to validate SMS Text is only keyboard character (abc, ABC, 123, ~!@#$%^&*()`[]{}|;':',./<>?)

Thanks...

like image 377
Ironman Avatar asked Dec 06 '22 22:12

Ironman


2 Answers

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.

like image 139
ptomli Avatar answered Dec 28 '22 10:12

ptomli


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.

like image 37
M'vy Avatar answered Dec 28 '22 10:12

M'vy