Jquery numeric validation

I have a form filed where I need to validate the filled to allow user to enter only positive numbers. So NUMBERS Only. I am using jquery.numeric plugin however, it allow to to input the minus '-'. How can I prevent this from happening

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ProculopsisConnect With a Mentor Commented:

Here is a simple alternative:

  <input onkeyup="this.value = this.value.replace( /\D/g, '' );" />
0
 
LAMASECommented:
Just add a mousedown/onchange/onblur event or whatever you want) and then

$('#inputfield').val(Math.abs($('#inputfield').val()));

Math.abs give the absolute value (without a sign).
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
the answer was not complete
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.