Form Input Validation Rules in Laravel

AuthorSumit Dey Sarkar

Pubish Date25 Mar 2023

categoryLaravel

In this tutorial we will see form input validation rules in laravel.

 

Form input validation rules in laravel

Laravel provides many type of validation rules by which you can validate user input.

Some of the commonly used validation rules in Laravel are:

 

  1. required: The field is required.
  2. filled: The field is required and not null.
  3. email: The field must be a valid email address.
  4. numeric: The field must be a numeric value.
  5. integer: The field must be an integer value.
  6. string: The field must be a string.
  7. array: The field must be an array.
  8. boolean: The field must be a boolean value.
  9. date: The field must be a valid date.
  10. date_format:format: The field must match the given date format.
  11. after:date: The field must be after the given date.
  12. before:date: The field must be before the given date.
  13. size:value: The field must be the given size.
  14. min:value: The field must be at least the given value.
  15. max:value: The field must not exceed the given value.
  16. unique:table,column,except,idColumn: The field must be unique in the specified table and column, except for the specified ID column (optional).
  17. exists:table,column: The field value must exist in the specified table and column.
  18. regex:pattern: The field must match the given regular expression pattern.
  19. alpha: The field must contain only letters (a-zA-Z).
  20. alpha_dash: The field may contain letters, numbers, dashes, and underscores.
  21. alpha_num: The field may contain only letters and numbers.
  22. distinct: The field values must be unique.
  23. in:foo,bar,...: The field value must be one of the specified values.
  24. not_in:foo,bar,...: The field value must not be one of the specified values.
  25. confirmed: The field must have a matching confirmation field (e.g. password and password_confirmation).
  26. gt:field: The field must be greater than the specified field.
  27. gte:field: The field must be greater than or equal to the specified field.
  28. lt:field: The field must be less than the specified field.
  29. lte:field: The field must be less than or equal to the specified field.
  30. json: The field must be a valid JSON string.
  31. mimetypes:text/plain,...: The field must be one of the specified MIME types.
  32. file: The field must be a valid file.
  33. image: The field must be a valid image file.
  34. timezone: The field must be a valid timezone identifier.
  35. url: The field must be a valid URL.
  36. active_url: The field must be a valid URL with a DNS record.
  37. regex:/^[a-zA-Z0-9\s]+$/: The field must match the given regular expression pattern.
  38. digits:value: The field must be numeric and have an exact length of value.
  39. digits_between:min,max: The field must be numeric and have a length between min and max.
  40. size:value: The field must have a file size equal to value (in kilobytes).
  41. dimensions:min_width=min, max_width=max,min_height=min, max_height=max: The field must have dimensions within the specified range.
  42. nullable: The field may be null. This rule is often used in combination with other rules to allow for optional input.
  43. sometimes: The field will only be validated if it is present in the input array. This rule is often used when you have optional input fields that should be validated if they are present.
  44. prohibited: The field is prohibited from being included in the input data. This rule can be useful if you want to explicitly disallow certain fields from being submitted.
  45. prohibited_if:anotherfield,value: The field is prohibited from being included in the input data if anotherfield has the given value.
  46. required_if:anotherfield,value: The field is required if anotherfield has the given value.
  47. required_unless:anotherfield,value: The field is required unless anotherfield has the given value.
  48. required_with:foo,bar,...: The field is required if any of the specified fields are present in the input data.
  49. required_with_all:foo,bar,...: The field is required if all of the specified fields are present in the input data.
  50. required_without:foo,bar,...: The field is required if none of the specified fields are present in the input data.
  51. required_without_all:foo,bar,...: The field is required if none of the specified fields are present in the input data.
  52. starts_with:value1,value2,...: The field value must start with one of the specified values.
  53. ends_with:value1,value2,...: The field value must end with one of the specified values.
  54. nullable_if:anotherfield,value: The field may be null if anotherfield has the given value.
  55. nullable_unless:anotherfield,value: The field may be null unless anotherfield has the given value.
  56. after:date: The field must be a date that comes after the given date.
  57. after_or_equal:date: The field must be a date that comes after or is equal to the given date.
  58. before:date: The field must be a date that comes before the given date.
  59. before_or_equal:date: The field must be a date that comes before or is equal to the given date.
  60. accepted: The field must be accepted (e.g. a checkbox that must be checked).
Comments 0

Leave a comment