I can not believe why such a simpel js code would not work!!
I want to replace all spaces with '^'. As you can see here I have tried both '\s*' & '\s+'. Neither worked! What do I miss here?
Thank you!
Code:
<html>
<head>
<script type="text/javascript">//<![CDATA[
function clean(str) {
var regex = /\s*/;
//var regex = /\s+/;
var nstr = str.replace(regex, '^');
alert('str = #' + str + '#, nstr = #' + nstr + '#');
// document.write('str = #' + str + '#, nstr = #' + nstr + '#');
}
//]]></script>
</head>
<body>
<form method="post" action="#" name="theForm">
Enter something:
<input type="text" onchange="clean(document.getElementById('userinput').value);" id="userinput" />
<input type="submit"/>
</form>
</body>
</html>
I want to replace all spaces with '^'. As you can see here I have tried both '\s*' & '\s+'. Neither worked! What do I miss here?
Thank you!