开发者

Why won't the integerValidation Method work?

开发者 https://www.devze.com 2023-03-08 11:42 出处:网络
In the method validateType it will call the method intgerValidation why is this giving me a blank page? When I try to run it but when I remove the intgerValidation method it works?

In the method validateType it will call the method intgerValidation why is this giving me a blank page? When I try to run it but when I remove the intgerValidation method it works?

public function validateType($validateThis, $validationType) {
    $validateThis;
    $validationType;
    if($validationType == 'int') {
        $this->integerValidation($validateThis));
    }
    if($validationType == 'string') {
        echo 'Is String';
    }
    if($valida开发者_StackOverflowtionType == 'email') {
        echo 'Is an Email';
    }

}
public function integerValidation($int) {
    $regex = "/^[0-9]{10}$/";
    if(preg_match($regex, $int)) {
        return true;
    }
    else {
        return false;
    }
}
        if($this->validateType(1234567890, 'int')) {
            echo 'Hello';
        }
        else {
            echo 'Number does not validate';
        }


PHP already have builtin functions for checking variable type

  • is_array
  • is_bool
  • is_callable
  • is_double
  • is_float
  • is_int
  • is_integer
  • is_long
  • is_null
  • is_numeric
  • is_object
  • is_real
  • is_resource
  • is_scalar
  • is_string

why dont use them. http://www.php.net/manual/en/ref.var.php


You have to put a return in the function validateType

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号