0

I need to use jquery 1.3.2 and would like to check if a string inside element contains a number. If not an alert should popup. Here is my code but it does not work. What is wrong with it? thank you

$(document).ready(function () {

var val = $(".xxx").val();   
var matches = val.match(/\d+/g);
if (matches != null) {
alert('number');
} 
});

html

<div class="xxx">aaa</div>
user1031743
  • 319
  • 1
  • 5
  • 14

1 Answers1

5

Use .html() or .text(), not .val(). .val() is for input elements:

var val = $(".xxx").html();

jsFiddle example

j08691
  • 204,283
  • 31
  • 260
  • 272