Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Help in textbox (http://www.go4expert.com/forums/help-in-textbox-t25041/)

darkbernz 21Feb2011 20:07

Help in textbox
hello everyone

i need help in may page. I need a textbox that only accepts alphabets. how it is done?:undecided


ManzZup 25Feb2011 20:11

Re: Help in textbox
alphabets == alpha_simple_capital??
you mean without numbers, slashes, commas ?

if its that you need to make a JS script that runs at the text change so that if the keyCode is not among the 'alphabet' values then its not added to the textbox
or simply a php script which detect it as an error and show the error message :D

darkbernz 25Feb2011 20:23

Re: Help in textbox
oh i see.. tnx manzzup.. :nice:
i will just create a JS.

hmm.. i wanna know how to use php script to detect numbers and special characters and show the error when these characters was inputed in my textbox..:nice:

ManzZup 26Feb2011 06:46

Re: Help in textbox
for the php script, you'll be getting the input form POST or GET as usual
and then run it through a func. just like the JS one

something like;

function isAllAlpha($str){
//your coding
return true or false

if(isAllAlpha($_POST['txt'])) echo "OK";
else echo "Error";

pein87 9Mar2011 03:28

Re: Help in textbox
php has isNumeric() and isNaN() functions you could use to check if its a number. Then create an array with all special characters and loop through it to see if the content contains them or use regex to perform a search for numbers and special characters. Its best if you did this on the client end though since it wont burn server resources doing it.

etiergjt 22Mar2011 07:57

Re: Help in textbox
I think regex is good to handle this
Get the input and see if its the type you want with preg_match

All times are GMT +5.5. The time now is 07:05.