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;
}
};
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
See here: Validate decimal numbers in JavaScript - IsNumeric()
function IsNumeric(sText) {
var Reg = new RegExp('^\\d+$');
var Result = sText.match(Reg);
if (Result)
return true;
else
return false;
}
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.