07-29-2009, 09:57 AM
|
#3 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by buildakicker
how to get rid of anything but letters and numbers.
|
I assume you also want to keep hyphens since they represent where whitespace is in the article title. Here's an amended version of your function, the two regular expressions have been changed to better suit what you're looking for.
JavaScript Code:
function updatelink() { var title = document.getElementById("articleTitle").value;
// 1. Replace whitespace with hyphen character var clean = title.replace(/\s+/g, "-"); // 2. Strip non-alpnanumeric-or-hyphen characters clean = clean.replace(/[^A-Z0-9-]/gi, "");
var postlink = document.getElementById("postlink"); postlink.firstChild.nodeValue = clean; }
|
|
|
|