I have a webapp, where people signup and get a sub domain under this app domain ( xx.app.com ) … for each subdomain there is a db that is attached to it grammatically and have the same name as the subdomain.
what i need is the right regex that works with the subdomain and off course a db name ( mysql if it matters ), it’s supposed to be lowercase & the length between 6 and 20 and the only allowed character is the ” – “, also numbers are banned …
i tried many times but it always go bad, .. some like : /([a-z-]){6,20}/
Thanks in advance 🙂
This would be a safer regex, since a subdomain cannot start with an hyphen:
As for the database name I believe it cannot contain an hyphen since it is the subtraction operator, so your best choice might be to either disallow hypens or replace them with underscores:
EDIT: Apparently @nikic is right, you can use hyphens as long as you backtick the database name.