00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( "lib/ezutils/classes/ezinputvalidator.php" );
00041
00042 class eZRegExpValidator extends eZInputValidator
00043 {
00044
00045
00046 function eZRegExpValidator( $rule = null )
00047 {
00048 $this->eZInputValidator();
00049 $this->RegExpRule = $rule;
00050 }
00051
00052 function setRegExpRule( $rule )
00053 {
00054 $this->RegExpRule = $rule;
00055 }
00056
00057 function validate( $text )
00058 {
00059 if ( !is_array( $this->RegExpRule ) )
00060 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00061 $accepted =& $this->RegExpRule["accepted"];
00062 if ( preg_match( $accepted, $text ) )
00063 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00064 $intermediate =& $this->RegExpRule["intermediate"];
00065 if ( preg_match( $intermediate, $text ) )
00066 return EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE;
00067 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00068 }
00069
00070 function &fixup( $text )
00071 {
00072 if ( !is_array( $this->RegExpRule ) )
00073 return $text;
00074 $intermediate =& $this->RegExpRule["intermediate"];
00075 $fixup =& $this->RegExpRule["fixup"];
00076 if ( is_array( $fixup ) )
00077 {
00078 $intermediate =& $fixup["match"];
00079 $fixup =& $fixup["replace"];
00080 }
00081 $text = preg_replace( $intermediate, $fixup, $text );
00082 return $text;
00083 }
00084
00085
00086 var $RegExpRule;
00087 }
00088
00089 ?>