Validation, Arrays, and functions o my!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pHatesp
Forum Newbie
Posts: 1
Joined: Wed Jan 23, 2008 10:11 am

Validation, Arrays, and functions o my!

Post by pHatesp »

Hello all,
New to php dev net but have a bit of a delima regarding a part of my code I'm racking my brain with, I know it's pretty simple but...

***** PLEASE USE THE

Code: Select all

TAG *****[/color]

Code: Select all

$valid_cc = array('30','31','32','33','34','350','351','352','353','354',
 '355','356','357','358','359','36','37','370','371','372','373','374','375','376','377','378','379','38','380','381','382','383','384','385','386','387','388','3883','389','39','40','41','42','420','421','422','423','424','425'
   ,'426','427','428','429','43','44','45','46','47','48','49','1');
  
  if (isset($_POST["mich_cc"])) {
        $intccode = str_replace("+","",numberOnly($_POST["mich_cc"]));
        $intccode = preg_replace("/^0?/","",$intccode); 
    }   
    
if (!in_array($intccode, $valid_cc)) {
  $errormsg = "cc_error";
  }
I'm trying to search through the valid_cc array for an EXACT match to what the user submitted ($intccode) It is checked for "+" and 0's but say if I submit "re1" It will say it's successful, I need to strip out all the letters from a users input into the form field. Then make sure that the submitted data is EXACTLY what is in the array otherwise it will pop the error msg. I hope this isn't too confusing, but appreciate the suggestions in advance. Glad to be here! :D

-p-hates-p
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Validation, Arrays, and functions o my!

Post by Christopher »

Try:

Code: Select all

$intccode = (int)preg_replace("/[^0-9]/", "", $_POST["mich_cc"]);
(#10850)
Post Reply