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
Share on other sites

What are some examples of valid input? This works for me, echoing "OK":

[code]
<?php
$_POST['bank_num'] = '1234567812345678';
if(!empty($_POST['bank_num']) && preg_match("/^[0-9]{16,17}$/", $_POST['bank_num'])){
echo "OK";
}
else{
echo "Not OK";
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.