I need to create a function that will get parameters as string and check if that string param contains only numbers or not. I tried doing this but I m not sure of the REGEX value.
function validateNum(x) {
var regex = /^\d+$/
var isValid = regex.test(x.value);
if (isValid) {
console.log("This is a Number. Thus, Accepted!.");
} else {
console.log("Only Numbers allowed.");
}
return isValid;
}
console.log(validateNum("12x3aj")) //Only Numbers allowed.
console.log(validateNum("12345")) //This is a Number. Thus, Accepted!.
Can anyone help me in this?