PHP Classes

File: tests/email.php

Recommend this page to a friend!
  Classes of Marco Marchiò   Regexp Builder   ???   Download  
File: tests/???
Role: Example script
Content type: text/plain
Description: Email validation
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change: .
Date: 15 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 "[email protected]: ".($regexp->testOn("[email protected]") ? "true" : "false"); //True
echo "<br>[email protected]: ".($regexp->testOn("[email protected]") ? "true" : "false"); //False
?>