Hola buenas tardes tengo este codigo y este me recive valores alfanumericos y quiero q solo me acepte valores numericos o q si escribo un valor q no sea numerico le salga un alert al usuario. soy nuevo en javascript... agradezco todas sus respuestas
jQuery(function($){
$('.cart').click(function(){
// Test to see if the price exceeds the minimum price (ie the Suggested Price):
if($('#minimum_price').length && parseFloat($('#minimum_price').val()) >= parseFloat($('input.name_price').val()))
{
alert('Please offer a price higher than the Minimum Price.');
return false;
}
// See if the price input is zero (because we want people to be able to choose a free option: NEEDS LOGIC FOR SET MINIMUM
else if(parseFloat($('input.name_price').val()) == 0)
{
return;
}
// Test to see if the input field has been left blank:
else if($('.name_price').length && !parseFloat($('input.name_price').val()))
{
alert('Por favor ingrese un valor numerico sin caracteres \n especiales y sin puntos ejemplo 250000');
return false;
}
// Test to see if input field is non-negative:
else if(parseFloat($('input.name_price').val()) < 0)
{
alert("Look here, old chap, that's just not on. Please enter a positive number, or zero. Tsk tsk.");
return false;
}
});
$('.cart').submit(function(){
$('<input name="price" />').val($('input.name_price').val()).attr('type',' hidden').appendTo($('form.cart'));
return;
});
});