ali_2kool2002 Posted February 16, 2007 Share Posted February 16, 2007 HI can anyone tel me how i can make an input area for the user to just enter numbers only in php that is not html... thanks Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/ Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 It can't be done.... If you have a text input element on a page and only want numbers in there you have to use javascript. That can be turned off so you shouls always validate the data in the php script accepting it. Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/#findComment-186331 Share on other sites More sharing options...
boo_lolly Posted February 16, 2007 Share Posted February 16, 2007 ^^^ exactly what mariner said. Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/#findComment-186370 Share on other sites More sharing options...
Psycho Posted February 16, 2007 Share Posted February 16, 2007 Here is an example of the javascript you can use to remove all characters except numbers from a field when the user moves off the field. However, as ToonMariner stated you should do the same thing on the server-side as well. <input type="text" onblur="this.value=this.value.replace(/\D/g,'');"> Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/#findComment-186382 Share on other sites More sharing options...
mbtaylor Posted February 16, 2007 Share Posted February 16, 2007 I would do a preg_replace on the server side: $_POST['var'] = preg_replace ("/[^0-9]/", "", $_POST['var']); What that says is strip out anything that is not a number (0-9). Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/#findComment-186390 Share on other sites More sharing options...
ali_2kool2002 Posted February 16, 2007 Author Share Posted February 16, 2007 :) :) :) :) thanks GUYS UR ALL GREAT!! NICE 1!! ne other way i cud recognise ur help let me know Link to comment https://forums.phpfreaks.com/topic/38776-solved-input-box-for-integer-values/#findComment-186426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.