Reputation: 13
//in here i want to insert only numbers.how can i do that?
function validate_proprty_price()
{
if($("#proprty_price").val() == '')
{
proprty_price.addClass("error");
proprty_price_span.text("Please Enter Price");
proprty_price_span.addClass("message_error2");
return false;
}
else{
proprty_price.removeClass("error");
proprty_price_span.text("");
proprty_price_span.removeClass("message_error2");
return true;
}
}
Upvotes: 2
Views: 202
Reputation: 50185
Trying to convert any string that is not a number with Number
will return NaN
, so:
var price = $("#proprty_price").val();
if (isNaN(Number(price)) {
// not a number, error message
}
Upvotes: 1
Reputation: 75083
Append jQuery Validation script to your code like:
<script
type="text/javascript"
src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js">
</script>
and just add number
and required
as a class to your input as
<input id="price" class="required number" />
Upvotes: 1