Skip to content Skip to sidebar Skip to footer

Check If A String Contains A Specific Number In Javascript

Possible Duplicate: JavaScript: string contains I want to check if a string contains a specific number in JavaScript, how can I rewrite the statement s contain d in below code?

Solution 1:

The easier way is to use index Of.

if(s.indexOf(d) > -1)

Solution 2:

var s = '11/14/2012';
var d = '14';
if (s.match(d)) {
   alert('Found');
}​

Post a Comment for "Check If A String Contains A Specific Number In Javascript"