One of my scripts receives a user-input value "name" that will serve as a domain or subdomain, hence I must make sure it contains only allowed characters, and must replace the rest.
My rules are as follows for that name that arrives in lower case:
- name must only contains A-Z (or a-z but converted earlier) or dots, anything else must be deleted to avoid cross-site scripting
- it may contain 1 or 2 dots (name.fr or name.co.uk) and if so must be flagged as a domain, but dots cannot be at the beginning, the end, or a dot follow another dot (ie usual domain rules)
- If the final value is a word only then I add .samplename.com at the end
- else the name is a doman and is used as such
I already have a good email validation test:
but it just returns an error if the email does not pass, here I must convert the chain.
Which PHP rules would help me do the above ?