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


PHP valid::numeric方法代码示例

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


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

示例1: save

 public function save(array $person = array(), $person_id = null)
 {
     $result = array('success' => false, 'error' => '');
     $valid = true;
     $person = $this->get_trimmed_allowed($person, array('space_id', 'email', 'x', 'y', 'active'));
     if (isset($person['space_id']) && !valid::digit($person['space_id'])) {
         $valid = false;
     }
     if (isset($person['email']) && !valid::email($person['email'])) {
         $valid = false;
     }
     if (isset($person['x']) && !valid::numeric($person['x'])) {
         $valid = false;
     }
     if (isset($person['y']) && !valid::numeric($person['y'])) {
         $valid = false;
     }
     if (isset($person['active']) && !valid::digit($person['active'])) {
         $valid = false;
     }
     if ($valid) {
         if ($person_id) {
             //UPDATE
             $this->db->from('people')->set($person)->where(array('id' => (int) $person_id))->update();
             $result['success'] = true;
         } else {
             // INSERT
             $new_person = $this->db->from('people')->set($person)->insert();
             $result['success'] = true;
             $person_id = $new_person->insert_id();
         }
         $person = $this->db->select('people.*')->from('people')->where(array('id' => $person_id))->get();
         $person = $this->result_as_array($person);
         $result['person'] = $person;
     } else {
         $result['error'] = "The supplied data was invalid";
     }
     return $result;
 }
开发者ID:samkeen,项目名称:Confab-Server,代码行数:39,代码来源:person.php

示例2: random

 /**
  * Tests the text::random() function.
  * @dataProvider random_provider
  * @group core.helpers.text.random
  * @test
  */
 public function random($type, $length = 8)
 {
     //$this->markTestIncomplete('Test for PHP 5.3 bug needs to be counted, Kohana is still supporting 5.2');
     $result = text::random($type, $length);
     if ((string) $type) {
         // Checking length
         $this->assertEquals(mb_strlen($result), $length);
         $pool = '';
         switch ($type) {
             case 'alnum':
                 $this->assertTrue(valid::alpha_numeric($result));
                 break;
             case 'alpha':
                 $this->assertTrue(valid::alpha($result));
                 break;
             case 'numeric':
                 $this->assertTrue(valid::numeric($result));
                 break;
             case 'nozero':
                 $this->assertTrue(is_numeric($result));
                 break;
             case 'hexdec':
                 $pool = '0123456789abcdef';
                 break;
             case 'distinct':
                 $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
                 break;
             default:
                 $pool = (string) $type;
         }
         if ($pool) {
             // PHP versions before 5.3 have a bug with preg_quote and it doesn't escape '-'
             $pool = version_compare(PHP_VERSION, '5.3', '>=') ? preg_quote((string) $pool, '/') : utf8::str_ireplace('-', '\\-', preg_quote((string) $pool, '/'));
             if (preg_match('/[' . $pool . ']*/u', $result, $match)) {
                 $this->assertEquals($match[0], $result);
             } else {
                 $this->assertTrue(FALSE);
             }
         }
     } else {
         // Checking length
         $this->assertEquals($result, '');
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:50,代码来源:Helper_Text_Test.php

示例3: validate_custom_form_fields

 /**
  * Validate Custom Form Fields
  * @param Validation $post Validation object from form post
  * XXX This whole function is being done backwards
  * Need to pull the list of custom form fields first
  * Then look through them to see if they're set, not the other way around.
  */
 public static function validate_custom_form_fields(&$post)
 {
     $custom_fields = array();
     if (!isset($post->custom_field)) {
         return;
     }
     /* XXX Checkboxes hackery
     			 Checkboxes are submitted in the post as custom_field[field_id-boxnum]
     			 This foreach loop consolidates them into one variable separated by commas.
     			 If no checkboxes are selected then the custom_field[] for that variable is not sent
     			 To get around that the view sets a hidden custom_field[field_id-BLANKHACK] field that
     			 ensures the checkbox custom_field is there to be tested.
     		*/
     foreach ($post->custom_field as $field_id => $field_response) {
         $split = explode("-", $field_id);
         if (isset($split[1])) {
             // The view sets a hidden field for blankhack
             if ($split[1] == 'BLANKHACK') {
                 if (!isset($custom_fields[$split[0]])) {
                     // then no checkboxes were checked
                     $custom_fields[$split[0]] = '';
                 }
                 // E.Kala - Removed the else {} block; either way continue is still invoked
                 continue;
             }
             if (isset($custom_fields[$split[0]])) {
                 $custom_fields[$split[0]] .= ",{$field_response}";
             } else {
                 $custom_fields[$split[0]] = $field_response;
             }
         } else {
             $custom_fields[$split[0]] = $field_response;
         }
     }
     $post->custom_field = $custom_fields;
     // Kohana::log('debug', Kohana::debug($custom_fields));
     foreach ($post->custom_field as $field_id => $field_response) {
         $field_param = ORM::factory('form_field', $field_id);
         $custom_name = $field_param->field_name;
         // Validate that this custom field already exists
         if (!$field_param->loaded) {
             // Populate the error field
             //$errors[$field_id] = "The $custom_name field does not exist";
             $post->add_error('custom_field', 'not_exist', array($field_id));
             return;
         }
         $max_auth = self::get_user_max_auth();
         $required_role = ORM::factory('role', $field_param->field_ispublic_submit);
         if (($required_role->loaded ? $required_role->access_level : 0) > $max_auth) {
             // Populate the error field
             $post->add_error('custom_field', 'permission', array($custom_name));
             return;
         }
         // Validate that the field is required
         if ($field_param->field_required == 1 and $field_response == "") {
             $post->add_error('custom_field', 'required', array($custom_name));
             return;
         }
         // Grab the custom field options for this field
         $field_options = self::get_custom_field_options($field_id);
         // Validate Custom fields for text boxes
         if ($field_param->field_type == 1 and isset($field_options) and $field_response != '') {
             if (isset($field_options['field_datatype'])) {
                 if ($field_options['field_datatype'] == 'email' and !valid::email($field_response)) {
                     $post->add_error('custom_field', 'email', array($custom_name));
                 }
                 if ($field_options['field_datatype'] == 'phonenumber' and !valid::phone($field_response)) {
                     $post->add_error('custom_field', 'phone', array($custom_name));
                 }
                 if ($field_options['field_datatype'] == 'numeric' and !valid::numeric($field_response)) {
                     $post->add_error('custom_field', 'numeric', array($custom_name));
                 }
             }
         }
         // Validate for date
         if ($field_param->field_type == 3 and $field_response != "") {
             $field_default = $field_param->field_default;
             if (!valid::date_mmddyyyy($field_response)) {
                 $post->add_error('custom_field', 'date_mmddyyyy', array($custom_name));
             }
         }
         // Validate multi-value boxes only have acceptable values
         if ($field_param->field_type >= 5 and $field_param->field_type <= 7) {
             $defaults = explode('::', $field_param->field_default);
             $options = array();
             if (preg_match("/[0-9]+-[0-9]+/", $defaults[0]) and count($defaults) == 1) {
                 $dashsplit = explode('-', $defaults[0]);
                 $start = $dashsplit[0];
                 $end = $dashsplit[1];
                 for ($i = $start; $i <= $end; $i++) {
                     array_push($options, $i);
                 }
             } else {
//.........这里部分代码省略.........
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:101,代码来源:customforms.php

示例4: valid_numeric_test

 public function valid_numeric_test()
 {
     $this->assert_true_strict(valid::numeric(-12.99))->assert_false_strict(valid::numeric('123_4'));
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:4,代码来源:validhelper.php

示例5: numeric

 /**
  * Tests the valid::numeric() function.
  * @dataProvider numeric_provider
  * @group core.helpers.valid.numeric
  * @test
  */
 public function numeric($input_numeric, $expected_result)
 {
     $result = valid::numeric($input_numeric);
     $this->assertEquals($expected_result, $result);
 }
开发者ID:swk,项目名称:bluebox,代码行数:11,代码来源:Helper_Valid_Test.php

示例6: random

 /**
  * Tests the text::random() function.
  * @dataProvider random_provider
  * @group core.helpers.text.random
  * @test
  */
 public function random($type, $length = 8)
 {
     $this->markTestIncomplete('Test for PHP 5.3 bug needs to be counted, Kohana is still supporting 5.2');
     $result = text::random($type, $length);
     if ((string) $type) {
         // Checking length
         $this->assertEquals(utf8::strlen($result), $length);
         $pool = '';
         switch ($type) {
             case 'alnum':
                 $this->assertTrue(valid::alpha_numeric($result));
                 break;
             case 'alpha':
                 $this->assertTrue(valid::alpha($result));
                 break;
             case 'numeric':
                 $this->assertTrue(valid::numeric($result));
                 break;
             case 'nozero':
                 $this->assertTrue(is_numeric($result));
                 break;
             case 'hexdec':
                 $pool = '0123456789abcdef';
                 break;
             case 'distinct':
                 $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
                 break;
             default:
                 $pool = (string) $type;
         }
         if ($pool) {
             if (preg_match('/[' . preg_quote((string) $pool, '/') . ']*/u', $result, $match)) {
                 $this->assertEquals($match[0], $result);
             } else {
                 $this->assertTrue(FALSE);
             }
         }
     } else {
         // Checking length
         $this->assertEquals($result, '');
     }
 }
开发者ID:swk,项目名称:bluebox,代码行数:48,代码来源:Helper_Text_Test.php


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