0

How to remove Special Character and alphabet from variable by jQuery.

I have

var test = +985

But I want to get value as

var another = 985

It should not allow character as well + as I am using it in Phone Code

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
NARGIS PARWEEN
  • 1,489
  • 3
  • 16
  • 26
  • 2
    Possible duplicate of [How to replace all occurrences of a string in JavaScript?](http://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript) – Binit Ghetiya Dec 02 '16 at 04:53

3 Answers3

2

try to something like this...

var inputString = "~!@#$%^&*()_+=`{}[]|\:;'<>,./?Some actual text to keep, maybe...",
var outputString = inputString.replace(/([~!@#$%^&*()_+=`{}\[\]\|\\:;'<>,.\/? ])+/g, '-').replace(/^(-)+|(-)+$/g,'');
Pravin Vavadiya
  • 3,195
  • 1
  • 17
  • 34
1

Might be duplicate of this

You just need to use replace function it's first parameter is symbol you want to replace and another is symbol or word you want to replace with.

For more info please visit Javascript replace function

var test = "+985";
var another = test.replace("+", "");

Community
  • 1
  • 1
Binit Ghetiya
  • 1,919
  • 2
  • 21
  • 31
1

Try this to extract number:

var test = +985;
alert(test+"".match(/\d+/));
Bhushan
  • 6,151
  • 13
  • 58
  • 91