Proper Case

This is the quickest way to get Proper Case in ASP/VBScript code that I’m aware of. Had need of it today, figured I’d stick it here, too. Just insert it at the top of your page, and Poof. Function available.

<script language=jscript runat=server>
function toTitleJscript(str) {
        return str.replace(/\s[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
</script>

And for kicks, here’s the similar Capitalize version:

<script language=jscript runat=server>
function toCapsJscript(str) {
        return str.replace(/\b[a-z]/g, function (str, n) { return str.toUpperCase(); });
}
</script>