From a search on the web.
The length of the SSID information field is between 0 and 32 octets. A 0 length information field indicates the broadcast SSID.
That's a bit misleading as the SSID is sometimes null terminated leaving only 31 characters available. Some firmware versions screw up if you use the full 32 characters.
The characters must also be printable, so no control characters are allowed. I'm fairly sure that a leading space is also not
allowed, but there doesn't seem to be anything specified.
Also: The following six characters are not allowed: ?, ", $, [, \, ], and +. In addition, the following three characters cannot be the first character: !, #, and ;.
You mileage may vary. And be aware some devices may not support the use of valid characters because they can not display them.