Reputation: 172
I am trying to figure out how can I validate an alphanumeric sender id for sending SMS via Twilio. I tried sending SMS with only numeric sender (not Twilio verified number, a random numeric sender id) and Twilio accepted that message. So I am not sure what exactly Twilio support in alphanumeric sender Id.
It would be helpful if Twilio API provides some Regular Expression for pattern matching or I could validate sender using API?
Any help in this regard would be highly appreciated.
Upvotes: 2
Views: 2259
Reputation: 2496
As of June 2024 the requirements are even more lax:
Alphanumeric Sender IDs can contain up to 11 characters from the following categories:
Upper-case letters A - Z
Lower-case letters a - z Numbers 0 - 9 Spaces
The following special characters can be used:
- +
- -
- &
- _
Alphanumeric Sender IDs must contain at least one letter.
I am using this Regex with apparent success:
^(?!^[0-9&_ -]{1,11}$)([A-z&_\-+0-9 ]){1,11}$
Upvotes: 0
Reputation: 9
stumbled on this and found that twilio is now accepting more characters, I have this regex in the app im working on.
^(?=.*[a-zA-Z])([a-zA-Z0-9 +-_&]{1,11})$
Upvotes: 0
Reputation: 1
The accepted answer appears to be out-of-date here - Twilio's documentation at https://www.twilio.com/docs/sms/services/api/alphasender-resource#alphasender-properties currently states:
An Alphanumeric Sender ID string, up to 11 characters. Valid characters are A-Z, a-z, 0-9, space and dash ( - ). An Alphanumeric Sender ID string cannot be comprised of only numbers.
By that definition, I believe this would be a more appropriate regex:
/^(?=.*[a-zA-Z \-])([a-zA-Z0-9 \-]{1,11})$/gm
Upvotes: -1
Reputation: 21720
Twilio developer evangelist here.
You will be able to find documentation about alphanumeric sender id's on the What is Alphanumeric Sender ID and how do I get started? page. Specifically, if you look under What characters can I use as the sender ID? you will find the following:
You may use any combination of 1 to 11 letters, A-Z and numbers, 0-9. Both lowercase and uppercase characters are supported as well as spaces. 1 letter and no more than 11 alphanumeric characters may be used.
A regular expression for this will vary depending on the programming language you're using, and in many cases you will find the language will have helpers for those things.
Also have a look at the list of countries where this functionality is supported.
Depending on the language you're using, the following pattern should do what you want, but like I said before you may wanna add limitations to the string using your language of choice.
/^(?=.*[a-zA-Z])(?=.*[a-zA-Z0-9])([a-zA-Z0-9 ]{1,11})$/m
A live version can be seen here.
Hope this helps you
Upvotes: 6