вот работает, но мне бы зациклить до букв/цифр
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>URL</title>
<script type="text/javascript">
function urlCode()
{
var urlCode = document.getElementById("urlCode").value;
var urlCode = urlCode.replace(/\s/g,"_");
var urlCode = urlCode.replace(/\./g,"-")
var urlCode = urlCode.replace(/\,/g,"-");
var urlCode = urlCode.replace(/[а-яА-Я]/g,"");
var urlCodeResult = document.getElementById("urlCodeResult");
urlCodeResult.style.textTransform = "lowercase";
var lastChar = urlCode.charAt(urlCode.length - 1);
alert ('Строка:'+urlCode);
alert ('Последний символ:'+lastChar);
if(lastChar = '-' || '_')
{
urlCode = urlCode.substring(0,urlCode.length-1);
lastChar = urlCode.charAt(urlCode.length - 1);
}
urlCodeResult.appendChild(document.createTextNode(urlCode));
}
</script>
</head>
<body>
<h2><a href="javascript:urlCode()">Convert</a></h2>
<form id="urlForm" onSubmit="urlCode()">
<input type="text" id="urlCode">
<input type="button" value="Convert" onClick="urlCode()">
</form>
<section>
<p id="urlCodeResult"></p>
</section>
</body>
</html>