Advertisement
gitlez

YA: Simple Phone Number Checking Mod3

May 22nd, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml…
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head>
  5.         <title>Phone numbers</title>
  6.         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  7.     </head>
  8. <body>
  9.     <?php
  10.         function validPhoneNum($i){ // Returns true if valid phone number, false if not
  11.             $numNums = strlen(preg_replace('/[^0-9]/', '', $i));
  12.             return (!($numNums !== 7 && $numNums !== 10) && !preg_match("/[^0-9\(\)\-\s\.]+/",$i));
  13.         }
  14.         $phoneNumbers = array("111-1111","(111) 111-1111","111-111-1111","111111",    "111.555.1234","","aaa-aaaa");
  15.        
  16.         // Table is merely to show functionality of function validPhoneNum();
  17.         echo '<table cellspacing="1" border="1">
  18.            <tr>
  19.                <th>Number</th>
  20.                <th>Valid</th>
  21.            </tr>';
  22.         foreach ($phoneNumbers as $phone) {
  23.             $valid = validPhoneNum($phone);
  24.             echo '<tr>
  25.                <td>' . $phone . '</td>
  26.                <td style="background-color: #' . (($valid)? '090' : '900') . ';">' . (($valid)? '' : 'NOT ') . 'Valid</td>
  27.            </tr>';
  28.         }
  29.         echo '</table>';
  30.     ?>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement