<commit_before><?php
/**
 *
 */

class FormIOField_Numeric extends FormIOField_Text
{
	// override the regex validator's error message for this field type
	public static $VALIDATOR_ERRORS = array(
		'regexValidator' => "Must contain numbers only"
	);

	// validate with regex validator internally
	protected $validators = array(
		array(
			'func' => 'regexValidator',
			'params' => array('/^\d*$/')
		)
	);

	// append 'behaviour' parameter to the input for JS validation
	protected function getBuilderVars()
	{
		$vars = parent::getBuilderVars();
		$vars['behaviour'] = 'numeric';
		return $vars;
	}
}
?><commit_msg>fixed numeric validation to allow floating point numbers and negatives<commit_after><?php
/**
 *
 */

class FormIOField_Numeric extends FormIOField_Text
{
	// override the regex validator's error message for this field type
	public static $VALIDATOR_ERRORS = array(
		'regexValidator' => "Must be a number",
		'greaterThanValidator' => "Must be greater than \$2",
		'lessThanValidator' => "Must be less than \$2",
		'minValueValidator' => "Must be at least \$2",
		'maxValueValidator' => "Must not be over \$2",
		'integerValidator' => "Must be a whole number",
	);

	// validate with regex validator internally
	protected $validators = array(
		array(
			'func' => 'regexValidator',
			'params' => array('/^(-?\d*\.?\d*)?$/')
		)
	);

	// append 'behaviour' parameter to the input for JS validation
	protected function getBuilderVars()
	{
		$vars = parent::getBuilderVars();
		$vars['behaviour'] = 'numeric';
		return $vars;
	}

	final protected function greaterThanValidator($expected) {
		return $this->value > $expected;
	}

	final protected function lessThanValidator($expected) {
		return $this->value < $expected;
	}

	final protected function minValueValidator($expected) {
		return $this->value >= $expected;
	}

	final protected function maxValueValidator($expected) {
		return $this->value <= $expected;
	}

	final protected function integerValidator() {
		return intval($this->value) == $this->value;
	}
}
?>
{'fraction_non_alphanumeric': 0.13977439921530163, 'fraction_numerical': 0.00196174595389897, 'mean_word_length': 4.340314136125654, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5509737', 'n_tokens_mistral': 663, 'n_tokens_neox': 613, 'n_words': 184}