I have a the following onkeyup command to test for, and remove, letters commas and dollar signs:
onkeyup="if (/(?:[a-zA-Z]|\s|,|\$)+/ig.test(this.value)) this.value = this.value.replace(/(?:[a-zA-Z]|\s|,|\$)+/ig,'')"
It works for everything except for the dollar signs.
Can anybody help me out here?
Thanks, Brds
HTML interprets your backslash as escaping the inline html string, not the regex. The following code prints $
.
<body onload='alert("\$");'> // prints '$', not '\$'
You need to escape twice, or move the regex out of the inline html and into a function.
I believe the correct answer is replace \$
with \\$
, as follows:
onkeyup="if (/(?:[a-zA-Z]|\s|,|\\$)+/ig.test(this.value)) this.value = this.value.replace(/(?:[a-zA-Z]|\s|,|\$)+/ig,'')"