# Validate

The `Validate` class in PHPFast is responsible for validating user input using the **Respect\Validation** library. It provides a collection of methods to check various types of data, such as **strings, numbers, dates, emails, and even JSON or IP addresses**.

This class helps ensure that data meets specific criteria before being processed or stored in a database, reducing errors and improving security.

## Methods in `Validate.php`

### **String & Character Validations**

<pre class="language-php"><code class="lang-php"><strong>// Ensures the string contains only letters (A-Z, a-z).
</strong><strong>public static function alpha() {
</strong>    return RespectValidator::alpha();
}

// Ensures the string contains only numeric digits (0-9).
public static function digit() {
    return RespectValidator::digit();
}

// Ensures the string contains only lowercase letters.
public static function lowercase() {
    return RespectValidator::lowercase();
}

// Ensures the string contains only uppercase letters.
public static function uppercase() {
    return RespectValidator::uppercase();
}
</code></pre>

Example:

```php
Validate::alpha()->validate("hello");         // True
Validate::digit()->validate("1234");          // True
Validate::uppercase()->validate("HELLO");     // True
Validate::lowercase()->validate("Hello");     // False
```

### **Number & Range Validations**

```php
// Ensures the value is a valid number.
public static function NumericVal() {
    return RespectValidator::NumericVal();
}

// Ensures the value falls within a specific range.
public static function between($min, $max) {
    return RespectValidator::between($min, $max);
}
```

Example:

```php
Validate::NumericVal()->validate(25);         // True
Validate::between(10, 50)->validate(30);      // True
Validate::between(10, 50)->validate(5);       // False
```

### **Email, URL, and IP Validations**

```php
// Validates an email format.
public static function email() {
    return RespectValidator::email();
}

// Checks if the value is a valid URL.
public static function url() {
    return RespectValidator::url();
}

// Validates an IP address.
public static function ip() {
    return RespectValidator::ip();
}
```

Example:

```php
Validate::email()->validate("test@example.com");     // True
Validate::url()->validate("https://example.com");    // True
Validate::ip()->validate("192.168.1.1");             // True
Validate::email()->validate("invalid-email");        // False
```

### **Password & Security Validations**

```php
// Ensures the value is not empty.
public static function notEmpty() {
    return RespectValidator::notEmpty();
}

// Ensures the value is exactly equal to another.
public static function equals($compareTo) {
    return RespectValidator::equals($compareTo);
}
```

Exampl&#x65;**:**

<pre class="language-php"><code class="lang-php"><strong>Validate::notEmpty()->validate("password");     // True
</strong>Validate::equals("admin")->validate("admin");   // True
Validate::equals("admin")->validate("user");    // False
</code></pre>

### **JSON, UUID, and Special Format Validations**

```php
// Ensures the string is a valid JSON format.
public static function json() {
    return RespectValidator::json();
}

// Ensures the string is a valid UUID.
public static function uuid() {
    return RespectValidator::uuid();
}

// Validates credit card numbers.
public static function creditCard() {
    return RespectValidator::creditCard();
}
```

Example:

```php
Validate::json()->validate('{"name": "John"}');                     // True
Validate::uuid()->validate("550e8400-e29b-41d4-a716-446655440000"); // True
Validate::creditCard()->validate("4111111111111111");               // True
```

### Validating an Array of Data (`check()`)

* Validates multiple fields based on predefined rules.
* Stores errors for fields that fail validation.

Example:

```php
$data = [
    'username' => 'john_doe',
    'email' => 'invalid-email'
];

$rules = [
    'username' => [
        'rules' => [Validate::alnum(), Validate::length(3, 20)],
        'messages' => ['Username must be alphanumeric.', 'Length must be between 3 and 20 characters.']
    ],
    'email' => [
        'rules' => [Validate::email()],
        'messages' => ['Invalid email format.']
    ]
];

$validator = new Validate();
if (!$validator->check($data, $rules)) {
    print_r($validator->getErrors()); // Output validation errors
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cmsfullform.com/documents/libraries/validate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
