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
- $phoneNumbers = array("111-1111","(111) 111-1111","111-111-1111","111111", "111.555.1234","","aaa-aaaa");
- foreach ($phoneNumbers as $phone) {
- $failures = 0;
- echo "<hr /><p>Checking '$phone'</p><hr />";
- $justNumbers = preg_replace('/[^0-9]/', '', $phone);
- if ( strlen($justNumbers) !== 7 && strlen($justNumbers) !== 10) {
- ++$failures;
- echo "<p><small>Warning: '$phone' must be 7 or 10 characters</small></p>";
- }
- if (preg_match("/[^0-9\(\)\-\s\.]+/",$phone)){
- ++$failures;
- echo "<p><small>Warning: '$phone' contains non numeric characters</small></p>";
- }
- if ($failures == 0) {
- echo "<p>'$phone' is valid</p>";
- }else{
- echo "<p>'$phone' is not valid</p>";
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement