Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/phone.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marco Marchiņ  >  Regexp Builder  >  tests/phone.php  >  Download  
File: tests/phone.php
Role: Example script
Content type: text/plain
Description: Phone number validation
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change: .
Date: 5 years ago
Size: 1,039 bytes
 

Contents

Class file image Download
<?php
require_once "../regexpBuilder.php";
/*
Phone number checking. Format: (999) 999-9999
LOGIC:
- (
- 3 numbers
- )
- zero ore more space characters
- 3 numbers
- hyphen
- 4 numbers
*/

$regexp=new regexpBuilder(CASE_INSENSITIVE);
$regexp->matchLineStart()    //Perform the check starting from the begin of the string
->match("(")    //(
->match(DIGIT_CHAR)->frequency(3)    //3 numbers
->match(")")    //)
->match(GENERAL_SPACE_CHAR)->frequency(ZERO_OR_MORE)    //Zero ore more space characters
->match(DIGIT_CHAR)->frequency(3)    //3 numbers
->match("-")    //hyphen
->match(DIGIT_CHAR)->frequency(4)    //4 numbers
->matchLineEnd();    //Match the end of the string

echo "(999) 999-9999: ".($regexp->testOn("(999) 999-9999") ? "true" "false"); //True
echo "<br>(999)999-9999: ".($regexp->testOn("(999)999-9999")? "true" "false"); //True
echo "<br>(999) 999.9999: ".($regexp->testOn("(999) 999.9999")? "true" "false"); //False
echo "<br>( 999 ) 999-9999: ".($regexp->testOn("( 999 ) 999-9999")? "true" "false"); //False
?>