How do I remove letters and dashes and dollar signs in a string using a regular expression?

前端 未结 6 1612
北海茫月
北海茫月 2020-12-23 21:33

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         


        
6条回答
  •  生来不讨喜
    2020-12-23 22:05

    This worked for me:

    $('.sumit').val().replace(/[^\d]/g, "");
    

    I tried Mike's answer with the capital \D instead of negating a \d first which for some reason didn't remove parenthesis and other punctuation for me. Negating \d works perfect.

    If you want to keep decimals, maybe put a dot and other symbols within the square brackets too.

    PS The environment in which I tested was Titanium SDK.

提交回复
热议问题