Skip to content

Conversation

@rojinc
Copy link

@rojinc rojinc commented Sep 25, 2025

Summary
This PR ensures character birthdates are realistic by enforcing a minimum age of 8 and a maximum age of 100. It adds front-end limits to the date picker, hard validation in CharacterValidator, a sensible default DOB, and new translation strings for friendly error messages.


What’s changed

1) app.js

  • DOB bounds: Adds computed properties minDOB and maxDOB (today−100y, today−8y).
  • Sensible default DOB: Sets registerData.date to yearsAgo(21) on mount and when resetting the form.
  • Clamping: Watches registerData.date and clamps any manual input/paste into the allowed range.
  • Helpers: Adds localISO() and yearsAgo() utilities so dates are timezone-safe (local YYYY-MM-DD).

2) validation.js

  • Age rules: Adds isTooYoung(value, 8) and isTooOld(value, 100); integrates them into the date validators array.
  • Date helpers: Adds parseISODate() and todayUTC() to avoid timezone edge cases.
  • Calendar validation: Keeps isValidDate focused purely on real dates; age range is enforced separately.

3) index.html (or your Vue template)

  • Date picker limits: Sets :min="minDOB" and :max="maxDOB" on <v-date-picker> so users can only pick valid birthdays.
<v-date-picker
  v-model="registerData.date"
  :min="minDOB"
  :max="maxDOB"
>
</v-date-picker>

4) Translations

  • Adds two new keys for age validation messages so the UI can explain why a date was rejected.

JS / i18n (if you keep translations in JS)

age_too_young: "Birthdate must make your character at least 8 years old.",
age_too_old: "Birthdate cannot make your character older than 100 years.",

Rationale

  • Prevents unrealistic/abusive ages and keeps servers consistent.
  • Enforces constraints both in UI (picker bounds) and logic (validator), so manual edits/pastes can’t bypass checks.
  • Handles timezone edge cases by normalizing to local date strings and UTC cutoffs.

How to test

  1. Open the character creation form.

  2. Verify the date picker won’t allow dates newer than today−8y or older than today−100y.

  3. Try manually typing a too-young date (e.g., 7y 364d ago) → should show age_too_young.

  4. Try manually typing a too-old date (e.g., 100y + 1 day ago) → should show age_too_old.

  5. Boundary checks:

    • Exactly 8 years ago → allowed.
    • Exactly 100 years ago → allowed.
  6. Try an invalid calendar date (e.g., 2023-02-30) → should show invalid_date.

  7. Confirm successful creation with an in-range DOB (e.g., 21y ago).


Backward compatibility

  • Non-breaking for existing characters.

Security / performance

  • Front-end only changes; no server API surface impacted.
  • Minimal overhead: simple date computations and validator checks.

Commit summary

  • Add age validation messages for character creation
  • Implement age validation in CharacterValidator
  • Modify default date and add DOB computed properties
  • Update date-picker min and max attributes

Checklist (maintainers/authors)

  • Have you loaded this code into an updated QBCore project and tested all functionality?

    • Yes
    • No
  • Does your code fit the style guidelines?

    • Yes
    • No
  • Does your PR fit the contribution guidelines?

    • Yes
    • No

Updated default date in registerData to 21 years ago and added computed properties for min and max date of birth.
Added age validation for character creation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant