using java script to check if string is numbers only

Go To StackoverFlow.com

0

using javascript to check if string is numbers only this is what i have but its not running any suggestions would the appreciated thanks much in advance. also if it is a string of numbers only then all numbers after the first two digits should be masked.

 var start = function RenderRC(CodeOwner) {

     var pattern = /^\d+$/;
     var Rcode = CodeOwner.toString();

     if (Rcode.valueOf.match(pattern)) {
        if (Rcode.length > 2) {
            var newcode = Rcode.substr(0, 2) + Array(Rcode.length - 2 + 1).join("*");
            return newcode;
        }
     } else {
        return Rcode;
     }
 }; 
2012-04-04 18:55
by chloe
use javascript IsNA - zod 2012-04-04 18:58
Rcode.valueOf is a function and doesn't have match metho - kirilloid 2012-04-04 18:58
Duplicate of http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeri - Avitus 2012-04-04 18:58
Did you check new answer - Pankaj 2012-04-11 11:09
referring to your answer - chloe 2012-04-11 14:40


0

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

See here: Validate decimal numbers in JavaScript - IsNumeric()

2012-04-04 19:00
by RyanS
thanks thanks - chloe 2012-04-04 19:04


0

function IsNumeric(sText) {
    var Reg = new RegExp('^\\d+$');
    var Result = sText.match(Reg);
    if (Result)
        return true;
    else
        return false;
}
2012-04-04 19:02
by Pankaj


0

Remove valueOf. and it should run fine

if (Rcode.match(pattern))
...

Or add the parenthesis to it to actually call the function:

if (Rcode.valueOf().match(pattern))
...

But I don't think that function call is needed.

2012-04-04 19:08
by Nick Rolando
Ads