I have got my complete project done but it is lacking this one requirement and i'm not able to solve this issue in my project myself.
Asked
Active
Viewed 2,116 times
2 Answers
3
Could you use CodeIgniter's form validation? And set a rule like this:
$this->form_validation->set_rules('yourfield', 'Your field\'s human name', 'required|integer');
This assumes that the field is called yourfield
.
After reading the comments, it seems like you want to check if value in the field is an integer using jQuery. I'd suggest looking into this plugin: jQuery - numeric
There's a good example of to use it here.
Here's the relevant code:
If you had an input like this:
<input class="integer" type="text" />
Then you can validate it, checking that it is an integer, like this:
$(".integer").numeric(false, function() { alert("Integers only"); this.value = ""; this.focus(); });
However, as JavaScript/jQuery is run on the client-side (and can be bypassed), I would stress that it is very important to also validate on the server-side, in this case using PHP. This excellent answer explains in more detail why both are important.
-
BUT I AM PLANNING TO GET JQUERY TYPE OF FORMAT. SO THAT ALL OTHER VALIDATIONS WORK IN ONE GLANCE. – saika May 14 '13 at 08:51
-
I'm not sure that I understand what you mean - do you want to use jQuery to validate the form? It might be useful to show the relevant code that you already have/what you have already tried. – jleft May 14 '13 at 09:10
-
i've used this code for image field validation:$("#button_SUBMIT").bind('click',function(e){ if($('#imagefield1').length==0){ alert('Photo 1 field required'); return false; } }); so the same type but for integer validation i would like but am feeling it difficult – saika May 14 '13 at 09:17
-
i have just givemn a est.value field and set its validation tatus to required without any condition but this is showing me error since it is even accepting alphabets – saika May 14 '13 at 09:19
-
@saika I've edited my answer to hopefully give you some useful information – jleft May 14 '13 at 09:43
-
i have done as adviced by you i have added the script tags along creating an id named estvalue but this is evn accepting alphabets and alphanumeric values. but there's no expected result could you let me know where exactly am i going wrong – saika May 14 '13 at 11:04
-
1Is the `jquery.numeric.js` script definitely being included? One issue is that you are getting _classes_ and _ids_ mixed up, you need to change this part of the script `$(".estvalue")` to `$("#estvalue")`. It would also be helpful if you edited the original question to include your formatted code, rather than just dumping it in a comment. – jleft May 14 '13 at 11:12
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