I made a function to check if a string contains illegal characters to be used as an URL for a new SharePoint site. This is useful to use when calling the Webs.Add function to programmatically create a new site in SharePoint where a user has provided the desired site url.
I took a look at the Create Site page in SharePoint. SharePoint calls a JavaScript function "IndexOfIllegalCharInUrlLeafName", which can be found in the "commonvalidation.js" on your SharePoint server. After the function call, SharePoint will check for a '+' character separately.
This is the function i've created. Illegal characters are replaced with a '-' character.
(you can download the code in a text file here)