I am runing the following jquery script:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#textThing").blur(function(){
var isNumber = $("#textThing").val().match(/^\d+/);
$("#p2").html(isNumber);
});
});
</script>
</head>
<body>
<input type="text" id="textThing" />
<p id="p2">Paragraph 2</p>
</body>
</html>
The problem is that the p2 never gives me anything when I deselect the input. What did I do wrong?
You need to say:
instead of:
…because
.match()returns an array if matched. See here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/matchHere’s a working version: http://jsfiddle.net/k45Ka/5/