Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="action.php" method="post">
- <p>Your name: <input type="text" name="name"/></p>
- <p>Your age: <input type="text" name="age" /></p>
- <p><input type="submit" /></p>
- </form>
- Hi <?php echo htmlspecialchars($_POST['name']); ?>.
- You are <?php echo (int)$_POST['age']; ?> years old.
- <form action="action.php" method="post">
- <p>Your Email: <input type="text" name="email"/></p>
- <p><input type="submit" /></p>
- </form>
- <?php
- $email = $_POST['email'];
- $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
- if (preg_match($regex, $email)) {
- echo $email . " is valid";
- } else {
- echo $email . " is invalid.";
- }
- ?>
- <br>
- <br>
- <?php
- $phone_numbers = array(
- '555-555-5555',
- '555 555 5555',
- '1(519) 555-4444',
- '1 (519) 555-4422',
- '1-555-555-5555',
- '1-(555)-555-25555',
- );
- $regex = "/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i";
- foreach( $phone_numbers as $number ) {
- echo $number . ': ' . ( preg_match( $regex, $number ) ? 'valid' : 'invalid' ) . '<br/>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement