-1

I am working upon validation of a field where in the field should be filled only with integers and validation that the field is needed is also given?

I inserted the script tags as follows:

<script type="text/javascript" src="jquery.numeric.js"></script>
<script>
jQuery(document).ready(function(){
$("#estvalue").numeric({
negative: false 
}, 
function() {
alert("No negative values");
this.value = "";
this.focus(); });
});
  </script>
<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="text" />
Antony
  • 14,900
  • 10
  • 46
  • 74
saika
  • 1
  • 1
  • 2
    He posted 3 same kind questiong within 2 hrs – PSR May 14 '13 at 12:31
  • http://stackoverflow.com/questions/16538303/i-want-my-field-to-accept-only-integers-and-i-have-kept-that-field-in-required-v – PSR May 14 '13 at 12:32
  • @PSR Yep. I am closing his other questions. – Antony May 14 '13 at 12:32
  • http://stackoverflow.com/questions/16539288/how-can-i-use-jquery-to-validate-a-field-that-should-be-filled-with-integers-onl – PSR May 14 '13 at 12:33
  • @saika why you are posted these many times – PSR May 14 '13 at 12:33
  • Take a look at the related question. [How to enforce only numeric values in textbox][1] [1]: http://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery – sriniris May 14 '13 at 13:01

1 Answers1

0

USE HTML5

<input type="number" min="0" />


<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="number" min="0" />

Validation Using JavaScript

<input name="Est_Value" id="estvalue" class="regi_input_1" style="width: 150px; height: 25px;" type="text" onkeypress="if ( isNaN( String.fromCharCode(event.keyCode) )){ alert('numbers only'); return false; }" />

Working Demo http://jsfiddle.net/cse_tushar/FEVrB/

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
  • He posted 3 same kind questiong within 2 hrs – PSR May 14 '13 at 12:32
  • if i'm using number type in my code then i'm getting a selection box, thanks for giving me some new idea but at present i dont want it i just want if anyone enters a variable a error msg should appear – saika May 14 '13 at 12:35