Framework  3.9
RegularExpressionValidator Class Reference

Tests wheteher a field's value matches the supplied regular expression. More...

+ Inheritance diagram for RegularExpressionValidator:
+ Collaboration diagram for RegularExpressionValidator:

Public Member Functions

 RegularExpressionValidator ($field, $title, $regexp, $message)
 
 writeClient ()
 
 validate ()
 
- Public Member Functions inherited from AbstractValidator
 AbstractValidator ($field, $title)
 

Public Attributes

 $regexp
 
 $message
 
- Public Attributes inherited from AbstractValidator
 $field
 
 $title
 

Detailed Description

Tests wheteher a field's value matches the supplied regular expression.

JDG 2/2012 - allow empty - validate nonempty if required with RequiredValidator.

Definition at line 949 of file validation.inc.

Member Function Documentation

◆ RegularExpressionValidator()

RegularExpressionValidator::RegularExpressionValidator (   $field,
  $title,
  $regexp,
  $message 
)

Definition at line 954 of file validation.inc.

955  {
956  $this->regexp = $regexp;
957  $this->message = $message;
958  $this->item =& $item;
959 
960  $this->AbstractValidator($field, $title);
961  }
AbstractValidator($field, $title)
Definition: validation.inc:53

◆ validate()

RegularExpressionValidator::validate ( )

Reimplemented from AbstractValidator.

Definition at line 982 of file validation.inc.

983  {
984  if ($this->readOnly) return "";
985 
986  //$exp = preg_replace("|([^/])|", "$1\\/", $this->regexp);
987  $exp = $this->regexp;
988  if ($_POST[$this->field] != "" && !preg_match("/{$exp}/i", $_POST[$this->field]))
989  {
990  $result = $this->message;
991  }
992 
993  return $result;
994  }

◆ writeClient()

RegularExpressionValidator::writeClient ( )

Reimplemented from AbstractValidator.

Definition at line 963 of file validation.inc.

964  {
965  trace("RegularExpressionValidator::writeClient", 3);
966 
967  if ($this->readOnly) return "";
968 
969  $script = <<<ENDSCRIPT
970 
971  if(form["{$this->field}"].value != "" &&
972  !form["{$this->field}"].value.match(/{$this->regexp}/i))
973  {
974  alert("{$this->message}");
975  return false;
976  }
977 ENDSCRIPT;
978 
979  return $script;
980  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

Member Data Documentation

◆ $message

RegularExpressionValidator::$message

Definition at line 952 of file validation.inc.

◆ $regexp

RegularExpressionValidator::$regexp

Definition at line 951 of file validation.inc.


The documentation for this class was generated from the following file: