Filtering the Numbers

Asked By Murugan V
30-Aug-10 07:16 AM
Earn up to 0 extra points for answering this tough question.
Hi All,

I want to filter the numbers from the string variable using javascript.

Lets Assume the value is 01-20/ABC-3

I want to extract the values as 01203.
I was trying to replace the string and special characters with empty space, which did not worked out.

If anybody had face the same issue, please share your thoughts/suggestions.

Thanks in Advance.

  re: Filtering the Numbers

Sagar P replied to Murugan V
30-Aug-10 07:25 AM
You can use Regular Exp for same like;

<input type="text" id="product13" name="product13" onblur="alert(this.id.replace(/\D/g,''));">

Replaces all the non-digit characters in the id with an empty string (essentially nothing) but returns all the digits in the id:

id="product13A13" ==> 1313

Also you can try something like this;

function somefunc(obj)
{
  return obj.id.match(/\d+/)[0];
}

http://bytes.com/topic/javascript/answers/169997-extract-number-string-get-13-product13

  re: Filtering the Numbers

Super Man replied to Murugan V
30-Aug-10 07:40 AM

// in this enter  value

 

<input type="text" id="product13" name="product13"  onkeyup ="isNumberKey()";">

 

 

// here it will show output

 

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

 

 

 

 

 

 

Script:

 

<script type="text/javascript">

    function isNumberKey() {

 

      var i = document.getElementById("product13").value.replace(/\D/g, '');

    

      document.getElementById("TextBox1").value = i;

     

    }

 

</script>

 

  re: Filtering the Numbers

Murugan V replied to Super Man
31-Aug-10 08:30 AM
Thanks Mr.Khan
Create New Account