0

How to check value in javascript variable for include number or not ?

eg: var test = "abcd1234";

this var test include lower case and number.

How to use javascript to check var value include number or not ?

I tried to use isNaN function

var test = "abcd1234";
var test = isNaN(test);
if(test === true)
{ alert("not include number");
else
{ alert("include number");

But this code alert not include number because isNaN will check all data of var. but i want to check only a part of var. How can i do that ?

mongmong seesee
  • 987
  • 1
  • 13
  • 24
  • Are you looking to simply find out whether a string contains at least one digit or is your criteria more sophisticated? Have you considered using regular expressions? – PM 77-1 Jan 13 '16 at 16:16

1 Answers1

0

You must use regex instead.

var test = /\d/.test("abcd1234");
if (test === true) {
  alert("include number");
} else {
  alert("not include number");
}
Lewis
  • 14,132
  • 12
  • 66
  • 87