[thelist] Stupid javascript String.replace() question
Roger Ly
rogerly at bareviking.com
Mon Dec 9 23:51:00 CST 2002
--
[ Picked text/plain from multipart/alternative ]
My O'Reilly says String.replace(regexpression , replaceString)
Returns the new string that results when all matches of the
regexpression parameter are replaced by the replaceString parameter.
Why doesn't this work for me?
function truncateCreditCard(ccNumber)
{
alert(ccNumber.replace(/\D+/, ''));
alert(ccNumber.replace(/\D*/, ''));
alert(ccNumber.replace(/[^0-9]*/, ''));
alert(ccNumber.replace(/[^0-9]+/, ''));
}
I want to strip out all non-numeric characters from a string that I am
passing in. Want to allow a string like "1111 2222 3333 4444" return
"1111222233334444". When I execute
truncateCreditCard("1111 2222 3333 4444"); I get four alerts that all
say:
11112222 3333 4444
where the first space is removed, but the others remain.
Sorry, maybe I've been up too long, but am I missing something stupid
here?
Roger
--
More information about the thelist
mailing list