I\'m trying to find all letters and dashes and dollar signs and remove them from a text box.
function numbersOnly()
{
if ($(\'.sumit\').val().indexOf([A
I really like Mark's answer. However, depending on your programming language (and RegEx engine) \d
matches characters like ४, or ৮, which are UTF-8 digits.
So if you only want digits from 0 to 9, use [^0-9.]
:
$('.sumit').val().replace(/[^0-9.]/g, "");
This is even faster if your RegEx engine is UTF-8 aware. An example Language, where this applies is python3 (http://docs.python.org/3/library/re.html - search for "\d"). The ECMA Standard, however, says that for JavaScript \d
equals [0-9]
.