Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I learned here http://regexone.com/
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- <?php if(isset($_GET['yourname'])):
- $pattern = "/[A-Z][a-z]* [A-Z][a-z]*/";
- preg_match($pattern, $_GET['yourname'], $matches);
- if(isset($matches[0]) && $_GET['yourname'] == $matches[0]): ?>
- <p>Your name is "<?php echo $_GET['yourname']; ?>"</p>
- <?php else: ?>
- <p>Your name is invalid!</p>
- <?endif;
- $pattern = '/([a-z0-9(._)]*)@([a-z0-9]*)\.([a-z(.)]*)/';
- preg_match($pattern, $_GET['youremail'], $matches);
- if(isset($matches[0]) && $_GET['youremail'] == $matches[0]): ?>
- <p>Your e-mail is "<?php echo $_GET['youremail']; ?>"</p>
- <?php else: ?>
- <p>Your e-mail is invalid!</p>
- <?endif;
- $pattern = '/(\d{2})(\d{7})/';
- preg_match($pattern, $_GET['yournumber'], $matches);
- if(isset($matches[0]) && $_GET['yournumber'] == $matches[0]): ?>
- <p>Your number is "<?php echo $_GET['yournumber']; ?>"</p>
- <?php
- switch($matches[1]):
- case 96:
- echo "<p>You are from cell phone service one!</p>";
- break;
- case 91:
- echo "<p>You are from cell phone service two!</p>";
- break;
- case 93:
- echo "<p>You are from cell phone service three!</p>";
- break;
- endswitch;
- else: ?>
- <p>Your number is invalid!</p>
- <?endif;
- else: ?>
- <form action="register_regex.php" method="get">
- <input type="text" name="yourname" placeholder="Write your 'FirstName LastName'"><br>
- <input type="text" name="youremail" placeholder="Write your e-mail"><br>
- <!--I know we can use type="e-mail"! Thanks to HTML 5 -->
- <input type="text" name="yournumber" placeholder="Introduce your phone number"><br>
- <input type="submit" value="Send">
- </form>
- <?php endif; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement