当前位置: 首页>>代码示例>>PHP>>正文


PHP TextField::validate方法代码示例

本文整理汇总了PHP中TextField::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP TextField::validate方法的具体用法?PHP TextField::validate怎么用?PHP TextField::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextField的用法示例。


在下文中一共展示了TextField::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Validates that the value matches the regular expression.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match($this->regex, $value, $this->matches)) {
         throw new ValidationError($this->message);
     }
 }
开发者ID:hbasria,项目名称:pjango,代码行数:14,代码来源:RegexField.php

示例2: testRegexpPrice

 public function testRegexpPrice()
 {
     \Input::setPost('test_rgxp_price', 'foobar');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertTrue($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20.00');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '-20');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20.-');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
 }
开发者ID:ralfhartmann,项目名称:isotope_core,代码行数:33,代码来源:IsotopeTest.php

示例3: validate

 /**
  * Validates that the value is a valid email address.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match('@^([-_\\.a-zA-Z0-9]+)\\@(([-_\\.a-zA-Z0-9]+)\\.)+[-_\\.a-zA-Z0-9]+$@', $value)) {
         throw new ValidationError(__("Invalid email address."));
     }
 }
开发者ID:hbasria,项目名称:pjango,代码行数:14,代码来源:EmailField.php

示例4: validate

 /**
  * Validates the the value is a valid URL (mostly).
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match('@^(http|ftp)s?://(\\w+(:\\w+)?\\@)?(([-_\\.a-zA-Z0-9]+)\\.)+[-_\\.a-zA-Z0-9]+(\\w*)@', $value)) {
         throw new ValidationError("Invalid URL.");
     }
 }
开发者ID:hbasria,项目名称:pjango,代码行数:14,代码来源:URLField.php

示例5: validate

 /**
  * Validates that the value matches the sscanf format.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     $this->matched = sscanf($value, $this->format);
     if (count($this->matched) === 0) {
         throw new ValidationError($this->message);
     }
 }
开发者ID:hbasria,项目名称:pjango,代码行数:15,代码来源:ScanField.php

示例6: testMaxLengthValidationSuccess

 /**
  * Tests the TextField Max Length Validation Success
  */
 public function testMaxLengthValidationSuccess()
 {
     $textField = new TextField('TestField');
     $textField->setMaxLength(5);
     $textField->setValue("John");
     // 4 characters, so should pass
     $result = $textField->validate(new RequiredFields());
     $this->assertTrue($result);
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:12,代码来源:TextFieldTest.php

示例7: validate

 public function validate()
 {
     if (!parent::validate()) {
         array_push($this->errors, "Invalid email address entered");
         $this->error = true;
         return false;
     } else {
         return true;
     }
 }
开发者ID:ekowabaka,项目名称:cfx,代码行数:10,代码来源:EmailField.php

示例8: validate

 public function validate()
 {
     if (!parent::validate()) {
         return false;
     }
     if ($this->value && filter_var($this->value, FILTER_VALIDATE_EMAIL) === false) {
         $this->errorMessage = "Please enter a valid e-mail address.";
         return false;
     }
     return true;
 }
开发者ID:mystlabs,项目名称:mistyforms,代码行数:11,代码来源:EmailField.php

示例9: validate

 public function validate()
 {
     if ($this->validate and is_array($this->validate)) {
         return parent::validate();
     } else {
         if ($this->min and !v::min($this->result(), $this->min)) {
             return false;
         }
         if ($this->max and !v::max($this->result(), $this->max)) {
             return false;
         }
     }
     return true;
 }
开发者ID:parasutcom,项目名称:styleguide,代码行数:14,代码来源:textarea.php

示例10: validate

 public function validate($object, $field_name)
 {
     if (!parent::validate($object, $field_name)) {
         return FALSE;
     }
     $value = $object->{$field_name};
     if (empty($value)) {
         return TRUE;
     }
     if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
         $this->setError('wrong_value', 'Field "' . $this->getLabel() . '" (' . $field_name . ') is not a valid mail address!');
         return FALSE;
     }
     return TRUE;
 }
开发者ID:mermetbt,项目名称:biome,代码行数:15,代码来源:EmailField.php

示例11: validate

 /**
  * Validates that the value is parsable as a date/time value.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     //if (!strtotime($value))
     //throw new ValidationError("Date/time format not recognized.");
 }
开发者ID:hbasria,项目名称:pjango,代码行数:13,代码来源:DateTimeField.php

示例12: validate

 /**
  * Validate input and set value
  */
 public function validate()
 {
     $varInput = $this->validator(deserialize($this->getPost($this->strName)));
     $this->saveTags(implode(",", array_filter(trimsplit(",", $varInput), 'strlen')));
     parent::validate();
 }
开发者ID:AgentCT,项目名称:tags,代码行数:9,代码来源:TagField.php

示例13: validate

 public function validate($data)
 {
     $url = $data[$this->name];
     $filtered_url = filter_var($url, FILTER_VALIDATE_URL);
     if ($filtered_url != $url) {
         $this->error("You must supply a valid URL.");
     } else {
         parent::validate($data);
     }
     return !$this->hasError;
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:11,代码来源:form.php

示例14: validate

 /**
  * Validates field's errors and returns them as array
  * @return array
  */
 public function validate()
 {
     if (is_null($this->size)) {
         $this->_addError("required option max_length was not set");
     }
     return parent::validate();
 }
开发者ID:Edke,项目名称:PerfORM,代码行数:11,代码来源:CharField.php

示例15: handle

 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     /** @var RootPackage $rootPackage */
     $rootPackage = $this->composer->getPackage();
     /** @var Config $config */
     $config = $this->composer->getConfig();
     $minimumStability = new \SelectMenu(array('id' => 'minimum-stability', 'name' => 'minimum-stability', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_minimum_stability'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_minimum_stability'][1], 'options' => array(array('value' => 'stable', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_stable']), array('value' => 'RC', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_rc']), array('value' => 'beta', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_beta']), array('value' => 'alpha', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_alpha']), array('value' => 'dev', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_dev'])), 'value' => $rootPackage->getMinimumStability(), 'class' => 'minimum-stability', 'required' => true));
     $preferStable = new \CheckBox(array('id' => 'prefer-stable', 'name' => 'prefer-stable', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][1], 'options' => array(array('value' => '1', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][0])), 'value' => $rootPackage->getPreferStable(), 'class' => 'prefer-stable', 'required' => true));
     $preferredInstall = new \SelectMenu(array('id' => 'preferred-install', 'name' => 'preferred-install', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_preferred_install'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_preferred_install'][1], 'options' => array(array('value' => 'source', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_source']), array('value' => 'dist', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_dist']), array('value' => 'auto', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_auto'])), 'value' => $config->get('preferred-install'), 'class' => 'preferred-install', 'required' => true));
     $configGithubOauth = $config->get('github-oauth');
     $githubOauth = new \TextField(array('id' => 'github-oauth', 'name' => 'github-oauth', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_github_oauth'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_github_oauth'][1], 'value' => $configGithubOauth['github.com'], 'class' => 'github-oauth'));
     $discardChanges = new \SelectMenu(array('id' => 'discard-changes', 'name' => 'discard-changes', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_discard_changes'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_discard_changes'][1], 'options' => array(array('value' => '', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_no']), array('value' => '1', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_yes']), array('value' => 'stash', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_stash'])), 'value' => (string) $config->get('discard-changes'), 'class' => 'github-oauth'));
     if ($input->post('FORM_SUBMIT') == 'tl_composer_settings') {
         $doSave = false;
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         $minimumStability->validate();
         $preferStable->validate();
         $preferredInstall->validate();
         $githubOauth->validate();
         $discardChanges->validate();
         if (!$minimumStability->hasErrors()) {
             $config['minimum-stability'] = $minimumStability->value;
             $doSave = true;
         }
         if (!$preferStable->hasErrors()) {
             $config['prefer-stable'] = (bool) $preferStable->value;
             $doSave = true;
         }
         if (!$preferredInstall->hasErrors()) {
             $config['config']['preferred-install'] = $preferredInstall->value;
             $doSave = true;
         }
         if (!$githubOauth->hasErrors()) {
             if ($githubOauth->value) {
                 $config['config']['github-oauth']['github.com'] = $githubOauth->value;
             } else {
                 unset($config['config']['github-oauth']['github.com']);
                 if (empty($config['config']['github-oauth'])) {
                     unset($config['config']['github-oauth']);
                 }
             }
             $doSave = true;
         }
         if (!$discardChanges->hasErrors()) {
             if ($discardChanges->value) {
                 $config['config']['discard-changes'] = $discardChanges->value == 'stash' ? 'stash' : (bool) $discardChanges->value;
             } else {
                 unset($config['config']['discard-changes']);
             }
             $doSave = true;
         }
         if ($doSave) {
             // make a backup
             copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~');
             // update config file
             $json->write($config);
         }
         $this->redirect('contao/main.php?do=composer&settings=dialog');
     }
     $template = new \BackendTemplate('be_composer_client_settings');
     $template->composer = $this->composer;
     $template->minimumStability = $minimumStability;
     $template->preferStable = $preferStable;
     $template->preferredInstall = $preferredInstall;
     $template->githubOauth = $githubOauth;
     $template->discardChanges = $discardChanges;
     return $template->parse();
 }
开发者ID:contao-community-alliance,项目名称:composer-client,代码行数:72,代码来源:SettingsController.php


注:本文中的TextField::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。