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 ?

1
  • 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? Commented Jan 13, 2016 at 16:16

1 Answer 1

0

You must use regex instead.

var test = /\d/.test("abcd1234");
if (test === true) {
  alert("include number");
} else {
  alert("not include number");
}

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.