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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted February 16, 2007 Share Posted February 16, 2007 ^^^ exactly what mariner said. Quote Link to comment 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,'');"> Quote Link to comment 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). Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.