Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to strip out letters from a string (e.g. XYZ321 --> 321)

Posted on 2004-03-25
Medium Priority
Last Modified: 2008-02-26
Dear All,

Cans omebody provide me with a function that I can feed a string into (consisting of letters and numbers only), that strips out all the letters to return a number. i.e. so I can pass in XYZ321 or 321XYZ and it will pass out just 321.

Many thanks.

Question by:webtechy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Accepted Solution

venkateshwarr earned 800 total points
ID: 10680779
You can use a regular expression.

<script language="JavaScript">
     var x="SDASDAS123123xyu";
     x = x.replace(/[A-Za-z]/gi, '');
LVL 31

Assisted Solution

GwynforWeb earned 800 total points
ID: 10680794
function strip(val){
return val.replace(/[a-z]/gi,'')
LVL 18

Assisted Solution

bobbit31 earned 400 total points
ID: 10680803
<script language=javascript>
      function stripAlpha(str) {
            var retVal = "";
            for (i=0;i<str.length;i++) {
                  if (!isNaN(str.charAt(i))) {
                        retVal += str.charAt(i);
            return retVal;

Author Comment

ID: 10681938
Cheers guys :-)

All very valid answers ...

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question