Bird
Raised Fist0
Laravelframework~10 mins

Available validation rules in Laravel - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Available validation rules
Start: Receive Input Data
↓
Apply Validation Rules
↓
Check Each Rule
↓
Pass
↓
All Pass?
No→Return Errors
Yes↓
Proceed with Valid Data
Input data is checked against each validation rule. If all pass, data proceeds; if any fail, errors are returned.
Execution Sample
Laravel
Validator::make($data, [
  'email' => 'bail|required|email',
  'age' => 'bail|integer|min:18'
]);
This code checks if 'email' is present and valid, and 'age' is an integer at least 18.
Execution Table
StepFieldRule CheckedConditionResultAction
1emailrequiredIs 'email' present?YesContinue to next rule
2emailemailIs 'email' a valid email format?YesContinue to next field
3ageintegerIs 'age' an integer?YesContinue to next rule
4agemin:18Is 'age' >= 18?NoFail validation, add error
5----Stop checking, return errors
💡 Validation stops after first failure; errors returned to user.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
emailuser@example.compresentvalid formatvalid formatvalid formatvalid
age161616integerfails min:18invalid
Key Moments - 2 Insights
Why does validation stop after the 'age' fails the min:18 rule?
Because Laravel stops checking further rules once a failure is found, as shown in execution_table step 5.
What happens if the 'email' field is missing?
The 'required' rule fails at step 1, and validation stops immediately returning an error.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of the 'email' field at step 2?
APasses email format
BFails email format
CMissing field error
DNot checked yet
💡 Hint
Check the 'Result' column for step 2 in the execution_table.
At which step does the validation fail for the 'age' field?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Look for the first 'Fail validation' action in the execution_table.
If the 'age' was 20, what would happen at step 4?
AValidation would skip this rule
BValidation would fail
CValidation would pass
DValidation would error out
💡 Hint
Refer to the 'Condition' and 'Result' columns for step 4 in the execution_table.
Concept Snapshot
Laravel validation rules check input fields step-by-step.
Rules like 'required', 'email', 'integer', 'min' apply conditions.
Validation stops at first failure and returns errors.
All rules must pass for data to be accepted.
Use Validator::make() with rules array to validate data.
Full Transcript
Laravel validation rules work by checking each input field against specified rules one by one. For example, the 'email' field is checked if it is present and if it has a valid email format. Then the 'age' field is checked if it is an integer and if it meets the minimum value of 18. If any rule fails, validation stops immediately and errors are returned. This process ensures only valid data proceeds further in the application.

Practice

(1/5)
1. Which Laravel validation rule ensures a field is not empty and must be present in the input data?
easy
A. required
B. nullable
C. sometimes
D. filled

Solution

  1. Step 1: Understand the required rule

    The required rule means the field must be present and not empty in the input data.
  2. Step 2: Compare with other rules

    nullable allows empty values, sometimes means the field is optional, and filled means if present, it cannot be empty.
  3. Final Answer:

    required -> Option A
  4. Quick Check:

    Field must be present and not empty = required [OK]
Hint: Remember: required means must be there and not empty [OK]
Common Mistakes:
  • Confusing 'nullable' with 'required'
  • Thinking 'sometimes' means required
  • Using 'filled' expecting it to require presence
2. Which of the following is the correct syntax to validate that a field named email must be a valid email address in Laravel?
easy
A. 'email' => 'required|email_address'
B. 'email' => 'required|valid_email'
C. 'email' => 'required|mail'
D. 'email' => 'required|email'

Solution

  1. Step 1: Identify the correct Laravel email validation rule

    Laravel uses email as the rule to check valid email format.
  2. Step 2: Check syntax correctness

    The syntax uses pipe | to separate rules, so 'required|email' is correct.
  3. Final Answer:

    'email' => 'required|email' -> Option D
  4. Quick Check:

    Email validation rule is 'email' [OK]
Hint: Use 'email' rule for email validation, no extra words [OK]
Common Mistakes:
  • Using 'email_address' instead of 'email'
  • Using 'mail' or 'valid_email' which are invalid
  • Forgetting to separate rules with pipe
3. Given the validation rule 'age' => 'required|integer|min:18', what happens if the input is age = 16?
medium
A. Validation passes because 16 is an integer
B. Validation passes because 'min' only applies to strings
C. Validation fails because 16 is less than the minimum 18
D. Validation fails because 16 is not required

Solution

  1. Step 1: Understand the rules applied

    The rules require the field to be present, an integer, and at least 18.
  2. Step 2: Check the input value against rules

    Input 16 is an integer and present, but less than 18, so it fails the min:18 rule.
  3. Final Answer:

    Validation fails because 16 is less than the minimum 18 -> Option C
  4. Quick Check:

    Integer less than min fails validation [OK]
Hint: min applies to numbers too, not just strings [OK]
Common Mistakes:
  • Thinking min only applies to string length
  • Ignoring the min rule when integer is less
  • Assuming integer rule alone is enough
4. What is wrong with this validation rule? 'username' => 'required|min:3|max'
medium
A. The max rule is missing a value
B. The min rule should be min:3,5
C. The required rule cannot be combined with min
D. The pipe separator | is missing

Solution

  1. Step 1: Analyze the max rule syntax

    The max rule requires a value like max:10 to specify the maximum length or number.
  2. Step 2: Identify the error in the rule string

    Here, max is used without a value, which is invalid syntax.
  3. Final Answer:

    The max rule is missing a value -> Option A
  4. Quick Check:

    Rules like max need a value after colon [OK]
Hint: Rules like max and min always need a number after colon [OK]
Common Mistakes:
  • Omitting the value after max or min
  • Using commas inside min rule incorrectly
  • Thinking required conflicts with min or max
5. You want to validate a password field that must be at least 8 characters and be confirmed by a matching password_confirmation field. Which validation rule set is correct?
hard
A. 'password' => 'required|string|min:8|regex:/[a-zA-Z]+[0-9]+/|confirmed'
B. 'password' => 'required|string|min:8|confirmed'
C. 'password' => 'required|min:8|alpha_num|confirmed'
D. 'password' => 'required|string|min:8|confirmed|same:password_confirmation'

Solution

  1. Step 1: Understand the confirmed rule

    The confirmed rule automatically checks for a matching password_confirmation field.
  2. Step 2: Check the rules for password complexity

    required|string|min:8 ensures presence, text type, and minimum length. The confirmed rule handles confirmation.
  3. Step 3: Evaluate other options

    alpha_num restricts to letters and numbers but may exclude symbols; regex is complex and not required here; same is redundant with confirmed.
  4. Final Answer:

    'password' => 'required|string|min:8|confirmed' -> Option B
  5. Quick Check:

    Use confirmed for matching password fields [OK]
Hint: Use 'confirmed' to check matching confirmation field [OK]
Common Mistakes:
  • Using 'same' instead of 'confirmed' for confirmation
  • Overcomplicating with regex when not needed
  • Forgetting to include 'required' or 'min:8'
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard