Thread: RegEx
View Single Post
Old 07-29-2009, 09:57 AM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by buildakicker View Post
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;
   
}
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
buildakicker (07-29-2009)