Commits

Timo Haberkern  committed 6a65eec Draft Merge

Merged in add-validator (pull request #1)

Fixed Ticket-ID

  • Participants
  • Parent commits 7e6e831, f0d7055

Comments (0)

Files changed (3)

File .idea/vcs.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="" />
+    <mapping directory="" vcs="hg4idea" />
   </component>
 </project>
 

File src/TP/CoreBundle/Validator/PhoneNumberValidator.php

+<?php
+namespace TP\CoreBundle\Validator;
+
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+
+class PhoneNumberValidator extends ConstraintValidator
+{
+    function validate($value, Constraint $constraint)
+    {
+        if (null === $value ||$value === '') {
+            return true;
+        }
+
+        if (preg_match('/^\d$/', $value)) {
+            return true;
+        }
+
+        $this->setMessage($constraint->message, array('{{ value }}'=>$value));
+        return false;
+    }
+}

File src/TP/CoreBundle/Validator/PhoneNumer.php

+<?php
+namespace TP\CoreBundle\Validator;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * @Annotation
+ */
+class PhoneNumber extends Constraint
+{
+    public $message = 'The string "{{ value }}" is not a valid phone number';
+
+    public function validatedBy()
+    {
+        return get_class($this).'Validator';
+    }
+}