Ejemplo n.º 1
0
 /**
  * Validate nick should not contain dashes
  *
  * @return array|bool|\string[]
  */
 public function validate()
 {
     $errors = [];
     $validator = new \Zend\Validator\Regex(array('pattern' => '/^[a-zA-Z0-9]*-[-a-zA-Z0-9]*$/'));
     if ($validator->isValid($this->getNickname())) {
         $errors[] = __('Nickname should not contain dashes');
     }
     if (!empty($errors)) {
         return $errors;
     }
     return parent::validate();
 }
Ejemplo n.º 2
0
 public function buildFilter()
 {
     $category = new Input('category');
     $category->getFilterChain()->attach(new StripTags())->attach(new StringTrim())->attach(new StringToLower());
     $category->getValidatorChain()->attach(new InArray(array('haystack' => $this->categories)));
     $title = new Input('title');
     $title->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $title->getValidatorChain()->attachByName('Alnum', array('allowWhiteSpace' => TRUE))->attachByName('StringLength', array('options' => array('min' => 6, 'max' => 128)));
     $price = new Input('price');
     $price->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $priceRegex = new \Zend\Validator\Regex(array('pattern' => '/^[0-9]{1,10}+(\\.[0-9]{1,2})?$/'));
     $priceRegex->setMessage('Preço deve ter no máximo 12 caracteres, incluindo opcionalmente 2 casas decimais separadas por ".".');
     $price->getValidatorChain()->attach($priceRegex);
     $dateExpires = new Input('date_expires');
     $dateExpires->setAllowEmpty(TRUE);
     $dateExpires->getValidatorChain()->attach(new InArray(array('haystack' => $this->dateExpires)));
     $description = new Input('description');
     $description->setAllowEmpty(TRUE);
     $description->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $description->getValidatorChain()->attachByName('StringLength', array('options' => array('max' => 4096)));
     $photoFilename = new Input('photo_filename');
     $photoFilename->setAllowEmpty(TRUE);
     $photoFilename->getValidatorChain()->attachByName('Regex', array('pattern' => '!^(http://)?[a-z0-9./_-]+(jp(e)?g|png)$!i'));
     $photoFilename->setErrorMessage('Photo must be a URL or a valid filename ending with jpg or png');
     $contactName = new Input('contact_name');
     $contactName->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $contactName->getValidatorChain()->attachByName('Regex', array('pattern' => '/^[a-z0-9., -]{1,255}$/i'));
     $contactName->setErrorMessage('Name should only contain letters, numbers, and some punctuation.');
     $contactEmail = new Input('contact_email');
     $contactEmail->setAllowEmpty(TRUE);
     $contactEmail->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $contactEmail->getValidatorChain()->attachByName('EmailAddress');
     $contactPhone = new Input('contact_phone');
     $contactPhone->setAllowEmpty(TRUE);
     $contactPhone->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $contactPhone->getValidatorChain()->attachByName('Regex', array('pattern' => '/^(\\([0-9]{2}\\))\\s([9]{1})?([0-9]{4})-([0-9]{4})$/'));
     $contactPhone->setErrorMessage('Contato deve ter o seguinte formato:(99) 9999-9999 ou (99) 99999-9999');
     $cityCode = new Input('cityCode');
     $cityCode->setAllowEmpty(TRUE);
     $cityCode->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $cityCode->getValidatorChain()->attach(new InArray(array('haystack' => array_keys($this->cities))));
     $deleteCode = new Input('delete_code');
     $deleteCode->setAllowEmpty(TRUE);
     $deleteCode->getFilterChain()->attach(new StripTags())->attach(new StringTrim());
     $deleteCode->getValidatorChain()->attachByName('Alnum', array('allowWhiteSpace' => TRUE));
     $this->add($category)->add($title)->add($price)->add($dateExpires)->add($description)->add($photoFilename)->add($contactName)->add($contactEmail)->add($contactPhone)->add($cityCode)->add($deleteCode);
 }
Ejemplo n.º 3
0
 public function filter($value)
 {
     $digitFilter = new \Zend\Filter\Digits();
     $valueFiltered = $digitFilter->filter($value);
     if ($valueFiltered) {
         $regexValidator = new \Zend\Validator\Regex('/^(084)+/');
         if ($regexValidator->isValid($valueFiltered)) {
             $valueFiltered = substr_replace($valueFiltered, '0', 0, 3);
         } else {
             $regexValidator->setPattern('/^(84)+/');
             if ($regexValidator->isValid($valueFiltered)) {
                 $valueFiltered = substr_replace($valueFiltered, '0', 0, 2);
             }
         }
         $regexValidator->setPattern('/^[0]/');
         if (!$regexValidator->isValid($valueFiltered)) {
             $valueFiltered = '0' . $valueFiltered;
         }
     }
     return $valueFiltered;
 }
Ejemplo n.º 4
0
 public function index15Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     //lap-trinh-2.php
     //laptrinh-2.html
     $patern = "#^[a-zA-Z0-9_-]+\\.(php|html)\$#imsU";
     $validator = new \Zend\Validator\Regex($patern);
     $input = "lap-trinh-2.phtml";
     if (!$validator->isValid($input)) {
         $message = $validator->getMessages();
         echo current($message);
     } else {
         echo "ok";
     }
     return false;
 }
 protected function changeCalendar(Calendar $calendar, $data)
 {
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $validator = new \Zend\Validator\Regex('/^\\d{1,2}:\\d{2} [PpAa][Mm]$/ui');
         if (!$validator->isValid($data['begin_day']) || !$validator->isValid($data['begin_day'])) {
             throw new \Exception('Time value is not valid!');
         }
         $user = $this->zfcUserAuthentication()->getIdentity();
         $userRepository = $em->getRepository(User::class);
         $user = $userRepository->find($user->getId());
         $calendar->setBeginDay(new \DateTime($data['begin_day']))->setEndDay(new \DateTime($data['end_day']))->setUser($user);
         $em->persist($calendar);
         $em->persist($user);
         $em->flush();
         $this->flashMessenger()->addSuccessMessage('Calendar was saved.');
         return $this->redirect()->toRoute('calendar', ['action' => 'edit', 'id' => $calendar->getId()]);
     } catch (\Exception $e) {
         $this->flashMessenger()->addErrorMessage($e->getMessage());
     }
     return $this->redirect()->toRoute('calendar', ['action' => 'create']);
 }
Ejemplo n.º 6
0
 public function ajaxaddbookAction()
 {
     /* @var $request \Zend\Http\Request */
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     $valEmail = new \Zend\Validator\EmailAddress();
     $valRequired = new \Zend\Validator\NotEmpty();
     $valMobile = new \Zend\Validator\Regex("/^[0-9]+\$/");
     if (!$valRequired->isValid($request->getPost('name'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('name' => 'Họ tên không được để trống')));
     }
     if (!$valRequired->isValid($request->getPost('mobile'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('mobile' => 'Điện thoại không được để trống')));
     }
     if (!$valMobile->isValid($request->getPost('mobile'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('mobile' => 'Điện thoại không hợp lệ')));
     }
     if (!$valRequired->isValid($request->getPost('email'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('email' => 'Email không được để trống')));
     }
     if (!$valEmail->isValid($request->getPost('email'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('email' => 'Email không hợp lệ')));
     }
     if (!$valRequired->isValid($request->getPost('cityId'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('cityId' => 'Thành phố không được để trống')));
     }
     if (!$valRequired->isValid($request->getPost('districtId'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('districtId' => 'Quận huyện không được để trống')));
     }
     if (!$valRequired->isValid($request->getPost('address'))) {
         return new JsonModel(array('code' => 0, 'messages' => array('address' => 'Địa chỉ không được để trống')));
     }
     $address = new \Address\Model\Book();
     $address->exchangeArray((array) $request->getPost());
     $address->setCreatedById($this->user()->getUser()->getId());
     /* @var $addMapper \Address\Model\BookMapper */
     $addMapper = $sl->get('Address\\Model\\BookMapper');
     $addMapper->saveAddress($address);
     if ($request->getPost("id")) {
         //If this action is used to edit a book
         return new JsonModel(['code' => 0]);
     } else {
         //Get the address that was just entered to DB
         $newaddr = $addMapper->searchAddress($address)[0];
         return new JsonModel(['code' => 1, 'address' => ['id' => $newaddr->getId(), 'name' => $newaddr->getName(), 'email' => $newaddr->getEmail(), 'mobile' => $newaddr->getMobile(), 'address' => $newaddr->getAddress(), 'cityId' => $newaddr->getCityId(), 'cityName' => $newaddr->getCityName(), 'districtId' => $newaddr->getDistrictId(), 'districtName' => $newaddr->getDistrictName()]]);
     }
 }
Ejemplo n.º 7
0
 public function validateQuestion($questions)
 {
     $messages = array();
     $stringValidator = new \Zend\Validator\Regex('/^a-zA-Z0-9 \\?|\\s/');
     foreach ($questions as $question) {
         // start question validation
         $isStringValid = $stringValidator->isValid($question);
         // check if string
         if (!$isStringValid) {
             array_push($messages, $question . " : is not a valid question ... please insert a valid one");
         }
     }
     return $messages;
 }