-7

How to remove character from strings (a-z, A to Z) using jQuery or JavaScript?

if str=avc234jw6;

I need only 2346.

2
  • 3
    yourString.replace(/[a-z]/ig,'') Commented Aug 3, 2016 at 8:05
  • 2
    Come on, did you at least try to google it? Commented Aug 3, 2016 at 8:05

2 Answers 2

1

A simple String.replace with regex /[a-z]/ig can do!

var str = "avc234jw6";
var no = parseInt(str.replace(/[a-z]/ig, ""));

console.log(no);

Sign up to request clarification or add additional context in comments.

Comments

0

Answer on non-edited question "How to remove char from strin?"

var removeChar = "a";
var string 	=	"abc abc abc";

function removeFromString(char, string){
var newString = "";
    for (var i = 0; i < string.length; i++) {
      if(string[i].toLowerCase() == char){
          continue;
      } else {
       newString += string[i];
      }
    }
    return newString;
}

$("#test").html(removeFromString(removeChar, string));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
test
</div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.