PDA

View Full Version : input validation


red_rose
03-06-2007, 06:50 AM
hello there

i would like to ask about PHP character type functions such as ctype_alnum, ctype_alpha and so on.

in my registration form, i am using ctype_alpha for my city and state input values validation. but when i type something like this : dfgfdg dfgfdg (with whitespace), it shows me error

actually i don't know whether it's correct to do it this way but what i want here is that, user can have whitespace but the value must consist of only alphabets and no any other type of character. below is the example of the code :


if(trim($city=='')){
$error_msg.="Please enter your City<br>"; }
else { if(!ctype_alpha($city)) {
$error_msg.="Please enter valid City<br>"; } }



could anyone tell me what's wrong and how should i do it? any help is appreciated. thank you

davidj
03-06-2007, 07:40 AM
this IF..

if(trim($city=='')){

im not sure if this is valid so you may have to test this.
it looks to me that the $city will never == " " because you are using trim so the trim might remove the value your looking for.

I would possibly check for white space using javascript first. Its a waste of a submit if your using the server to validate and fail on submission

red_rose
03-06-2007, 08:18 AM
i tried removing 'trim', but the validation doesn't work properly :

- wen i click the button, it will save the value in the db ( the one i entered),
i saw from the echo of sql and also checked in the db, even thought it
contains numbers
- at the same time, it will also show me the
message Please enter valid City

i am really confused with this

davidj
03-06-2007, 08:22 AM
i will try to help later on

i dont have a machine at home anymore to assist 100%

i might be able to point you in the right direction later on...

Hint: i would create a validation function and pass all your content in there but i would use javascript to catch any wrongly keyed data initialy

davidj
03-07-2007, 09:15 AM
in my registration form, i am using ctype_alpha for my city and state input values validation. but when i type something like this : dfgfdg dfgfdg (with whitespace), it shows me error

if you are validating on address fields why not remove the chance of error by creating dropdowns with fixed values. Then there is no chance of error