...

View Full Version : inout filter



esytiger202
08-05-2007, 04:05 PM
Hello all
I use a script which is in smarty , the inputs only validates by javascript.
I wanna use a php script to filter some fields , to pass only digits or alphabet.

can you help me ? to use any script BESIDE the main script to control inputs before get POST ?

(Im not a php developer , :( )

Thanks all :thumbsup:

JordanW
08-05-2007, 04:21 PM
You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


The PHP for checking for numbers or alphabet characters only is:



if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
echo "VALID!";
} else {
echo "INVALID!";
}

esytiger202
08-05-2007, 08:59 PM
You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


The PHP for checking for numbers or alphabet characters only is:



if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
echo "VALID!";
} else {
echo "INVALID!";
}


Thanks, but
I wanna 1 filed to accept digits ONLY , I tried ereg('[0-9]') but if we combine alphabet and digit it cant stop the post for example :

test ===> returns INVALID but test123 ===>returns VALID
I need it only to accept nombers,

Also I need another input to accept ONLY alphabet , no digit..

I tested also preg_match("/[^0-9]+$/ ") but the same problem, accepts combination of nomber and alphabet.

Thanks

esytiger202
08-05-2007, 10:19 PM
You cannot control what a user type in a text field before it is sent to the server (as PHP is Server-Side) i.e. before the data is posted. Once posted however you can check what has been inputted and show an error message if it isn't alphanumerical. Javascript is Client-Side so would be able to filter text-inputs


The PHP for checking for numbers or alphabet characters only is:



if (ereg('[A-Za-z0-9]',$_POST['inputfield'])){
echo "VALID!";
} else {
echo "INVALID!";
}


It was ok, I made mistake, thanks Jordan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum