Jump to content

preg_match problem


KevinM1

Recommended Posts

I have a simple form in which I ask the user to enter in the telephone number of their credit card company.  I try validating that it's either a 16 digit number (normal telephone number) or a 17 digit number (telephone number beginning with a 1, like 1800 something).  Unfortunately, it doesn't seem to be working as I keep getting my error message which is created if the field fails the test.

My validation is:
[code]
<?php

  if(!empty($_POST['bank_num']) && preg_match("/^[0-9]{16,17}$/i", $_POST['bank_num'])){
      $bankNum = $_POST['bank_num'];
      $bn = TRUE;
  }

  else{
      $errMessage .= "Please enter your credit card's telephone number!<br />\n";
  }

?>
[/code]

I know I don't need to tell it to be case insensative in this case, but I wouldn't think that would be the cause of the error (especially as both validating one's home phone number and their credit card's CID seem to work correctly with it like that).  Any ideas on why I'm getting my error message, even if I input the correct number of digits?
Link to comment
https://forums.phpfreaks.com/topic/33931-preg_match-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.