<html>
<head>
<script type="text/javascript">
function urltitle(title)
{
// Create the url friendly title
var url = title
.toLowerCase() //change everything to lowercase
.replace(/^\s+|\s+$/g, "") //trim leading and trailing spaces
.replace(/[&]+/g, "and") //replace ampersand
.replace(/[#]+/g, "sharp") //replace pound
.replace(/[@]+/g, "at") //replace at
.replace(/[%]+/g, "percent") //replace percent
.replace(/[+]+/g, "plus") //replace plus
.replace(/[-|\s]+/g, "_") //replace spaces and hyphens to underscore
.replace(/[^a-z0-9_]+/g, "") //remove all non-alphanumeric characters except the underscore
.replace(/[_]+/g, "_") //remove duplicate underscores
.replace(/^_+|_+$/g, "") //trim leading and trailing underscores
;
document.getElementById('title_url').value = url;
}
</script>
</head>
<body>
<input type="text" onkeyup="javascript:urltitle(this.value);" />
<input type="text" id="title_url" />
</body>
</html>
No comments:
Post a Comment