Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
WEB: Web Design Forum- TutorialsDreamweaver Forum- TutorialsFlash Forum- TutorialsWeb StreamingTraining

php conditional

Cow Forums : Adobe Dreamweaver
php conditional
by Neil Bradley on Oct 13, 2008 at 10:43:23 pm

Working on a form containing conditional rejoins in php.
I am using is_numeric to test if the form contains a number value however not sure what to use to the is the value contains characters.

Any help appreciated.


Respond to this post   •   Return to posts index

Re: php conditional
by Abraham Chaffin on Oct 14, 2008 at 9:11:27 pm

You could do something like

if($input==preg_replace('|[^a-zA-Z]|','',$input)){
true;
}else{
false;
}


Abraham

Respond to this post   •   Return to posts index

Re: php conditional
by Neil Bradley on Oct 14, 2008 at 9:32:57 pm

The code I am using for a similar form processing only numbers is:

if (!(is_numeric($_POST['mobile']))
header("Location: register.php?error=notnumeric");
exit;
}

This code figures out that there are no numbers being sent via the form and returns a message back to the form saying "display my hidden message".
I see how your code works but unsue how to insert it into my own code. How would I adapt your code here:

if($input==preg_replace('|[^a-zA-Z]|','',$input)){
true;
}else{
false;
}

...to work with my intetion of checking for characters raher than numbers?

Cheers,
Neil






Respond to this post   •   Return to posts index


Re: php conditional
by Abraham Chaffin on Oct 14, 2008 at 9:44:49 pm

The code below would check if the mobile post value is only a-z or A-Z. Then redirect it to your error page.


$input=$_POST[mobile];

if($input==preg_replace('|[^a-zA-Z]|','',$input)){
header("Location: register.php?error=not-alphabetic-only");
exit;
}



Abraham

Respond to this post   •   Return to posts index

Re: php conditional
by Neil Bradley on Oct 14, 2008 at 9:56:42 pm

Nice
I see how this works:
$input=$_POST[mobile];

if($input==preg_replace('|[^a-zA-Z]|','',$input)){
header("Location: register.php?error=not-alphabetic-only");
exit;
}

Just for fun this time if I wanted to check to see if the form contained any characters or any numbers (basically an entry of any number or character combination) how would this affect the code configuration?



Respond to this post   •   Return to posts index

Re: php conditional
by Abraham Chaffin on Oct 14, 2008 at 11:21:49 pm

In this example you could edit the regular expression and add 0-9 as another qualifier. "|[^a-zA-Z0-9]|"


$input=$_POST[mobile];

if($input==preg_replace('|[^a-zA-Z0-9]|','',$input)){
header("Location: register.php?error=not-alphabetic-only");
exit;
}


Abraham

Respond to this post   •   Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINEDVDsBOOKSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]