简体   繁体   English

大于和小于精确匹配值

[英]Greater than and less than exact match value

I have been working on a function and the validation is to ensure that input in the field is exactly what is in the $cash variable defined, i succeeded in using greater than function but this allows values greater than what the user has, so it does not get exact figure of what the user has, if user cash is 300 then anything above 300 is valid and okay, but i want the validation to be strictly on the value exactly.我一直在研究一个函数,验证是为了确保字段中的输入与 $cash 变量中定义的完全一致,我成功地使用了大于函数,但这允许值大于用户拥有的值,所以它确实没有得到用户拥有什么的确切数字,如果用户现金是 300,那么 300 以上的任何东西都是有效的,没问题,但我希望验证严格按照价值进行。

add_filter( 'gform_field_validation_9_7', 'custom_validationc', 10, 4 );
function custom_validationc( $result, $value, $form, $field ) {

$current_user = wp_get_current_user();
$number = $current_user->USERPIN2;

if ( $result['is_valid'] && $value < $number ) {
    $result['is_valid'] = false;
    $result['message'] = 'You must enter exactly the amount on your cash balance.';
}
return $result;

} }

My problem is that i want the exact value of $cash not by using greater than functions.我的问题是我想要 $cash 的确切值而不是使用大于函数。 And i have tried $value === $cash - But nothing works.我已经尝试过 $value === $cash - 但没有任何效果。 only works when i use the greater than function or less than function for validation.仅当我使用大于函数或小于函数进行验证时才有效。

If it needs strictly validation, you need to use operator '===', more info is here: How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?如果需要严格验证,则需要使用运算符“===”,更多信息在这里: PHP 等式(== 双等式)和身份(=== 三等式)比较运算符有何不同?

Also, you can use another conditions, so, the code may be like that:此外,您可以使用其他条件,因此,代码可能是这样的:

if ( intval($value) === $cash )
  echo "perfect";

Or或者

if ( intval($value) >= $cash )
  echo "perfect";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM