Check string is valid number

Hello Friend,

Here we have give demo to check string is valid number or not.

Download Source code:=>StringIsValidNumber

1. JavaScript Code

<script type="text/javascript">

        function checkNumber() {
            var str = document.getElementById("<%=txtNumber.ClientID %>").value;
            var validNumber = "";
            var n = str.split(" ");
            for (i = 0; i < n.length; i++) {
                if (isNumber(n[i])) {
                    validNumber = n[i] + "," + validNumber;
            document.getElementById("<%=lblValidNumber.ClientID %>").innerHTML = validNumber;
            return false;
        function isNumber(n) {
            return !isNaN(parseFloat(n)) && isFinite(n);


2. HTML Code

<table width="80%" border="1px">
<tr align="center">
<td colspan="2" align="center">Here you can chcek your string is valid number or not</td>
<tr align="center">
<td align="right">Your String:</td>
<td align="left">Pass your string is like ("sss as 12 asdas 123123") and out put is 12,123123</td>
<tr align="center">
<td align="right"></td>
<td align="left">Valid Number is:</td>

3. Final Output is look like below.




No comments

Leave a Reply

1 × 4 =