Forum Discussion

abrar22's avatar
abrar22
Frequent Contributor
9 years ago

Trim Special Characters from Numbers

Hi,    I want to remove special characters from number. Can I use replace function ?   var Notional= Getter.vGetPropertyVal(WTbx_SingleLegNotional,'Text'); var Desired= Notional.replace(/[!@#$%^...
  • djadhav's avatar
    9 years ago

    You can try using this:

    var Notional= Getter.vGetPropertyVal(WTbx_SingleLegNotional,'Text');
    var Desired= Notional.replace(/\D/g, "");

     

     

    This code works as shown below

     

    function ReplaceSpChr(){
        var s = "/[!@2#$4%^&1*]0/g00,0";
        // Create regular expression pattern.
        var re = /\D/g;
        // Use replace
        var r = s.replace(re, "");
        return(r);
    
        // Output:  2410000
    }