shirvo Posted December 17, 2006 Share Posted December 17, 2006 I want a text box to only allow numbers in it. So when someone enters a phone number they have to put numbers, this is so people dont just enter crap Quote Link to comment Share on other sites More sharing options...
zq29 Posted December 17, 2006 Share Posted December 17, 2006 If you want it to block them in real time, you'll need some JavaScript to do that, otherwise, if you just want to validate it after post, you can check it with is_numeric(). Quote Link to comment Share on other sites More sharing options...
shirvo Posted December 17, 2006 Author Share Posted December 17, 2006 how do i use that Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Share Posted December 17, 2006 i dont know about is_numeric()but i can help you with "^[0-9]*"[code]<?php$phone = $_POST['phone_no'];//where it gets the phone no. from the form.$regex ="^[0-9]*";//this is where it checks if it is all numbersif(!eregi($regex,$phone)){echo "your phone number is not in numbers, ie. are you from mars??";}?>[/code]got it?i havnt try it myself... so it might not work.Ted Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted December 17, 2006 Share Posted December 17, 2006 PCRE > POSIX regex :)eg,[code]$phone = $_POST['phone_no'];//where it gets the phone no. from the form.if(preg_match('/\d+/', $phone) == 0) echo "your phone number is not in numbers, ie. are you from mars??";[/code]Alternativly, use is_int or is_numeric... 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.