Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml…
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Phone numbers</title>
- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
- </head>
- <body>
- <?php
- function validPhoneNum($i){ // Returns true if valid phone number, false if not
- $numNums = strlen(preg_replace('/[^0-9]/', '', $i));
- return (!($numNums !== 7 && $numNums !== 10) && !preg_match("/[^0-9\(\)\-\s\.]+/",$i));
- }
- $phoneNumbers = array("111-1111","(111) 111-1111","111-111-1111","111111", "111.555.1234","","aaa-aaaa");
- // Table is merely to show functionality of function validPhoneNum();
- echo '<table cellspacing="1" border="1">
- <tr>
- <th>Number</th>
- <th>Valid</th>
- </tr>';
- foreach ($phoneNumbers as $phone) {
- $valid = validPhoneNum($phone);
- echo '<tr>
- <td>' . $phone . '</td>
- <td style="background-color: #' . (($valid)? '090' : '900') . ';">' . (($valid)? '' : 'NOT ') . 'Valid</td>
- </tr>';
- }
- echo '</table>';
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement