Solved

Jquery numeric validation

Posted on 2011-02-18
3
783 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:erikTsomik
3 Comments
 
LVL 4

Expert Comment

by:LAMASE
ID: 34930745
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
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 34931843

Here is a simple alternative:

  <input onkeyup="this.value = this.value.replace( /\D/g, '' );" />
0
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 35114294
the answer was not complete
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now