PHP Classes

File: tests/email.php

Recommend this page to a friend!
  Classes of Marco Marchiņ   Regexp Builder   tests/email.php   Download  
File: tests/email.php
Role: Example script
Content type: text/plain
Description: Email validation
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change: .
Date: 14 years ago
Size: 1,008 bytes
 

Contents

Class file image Download
<?php
require_once "../regexpBuilder.php";
/*
Email checking.
LOGIC:
- one or more letter, number or dot characters
- @
- one or more letter, number or dot characters
- dot
- Letters repeated between 2 and 4 times
*/

$regexp=new regexpBuilder(CASE_INSENSITIVE);
$regexp->matchLineStart() //Perform the check starting from the begin of the string
->matchOneOfTheseChars(LETTER_CHAR.DIGIT_CHAR.".")->frequency(ONE_OR_MORE) //Letter, number or dot repeated on ore more times
->match("@") //@ sign
->matchOneOfTheseChars(LETTER_CHAR.DIGIT_CHAR.".")->frequency(ONE_OR_MORE) //Letter, number or dot repeated on ore more times
->match(".") //dot
->matchOneOfTheseChars(LETTER_CHAR)->frequency(2,4) //Letters repeated between 2 and 4 times
->matchLineEnd(); //Match the end of the string

echo "example@email.com: ".($regexp->testOn("example@email.com") ? "true" : "false"); //True
echo "<br>example@email.comwrong: ".($regexp->testOn("example@email.comwrong") ? "true" : "false"); //False
?>