Skip to content

Regex Expressions as Actions #964

Discussion options

You must be logged in to vote

You need to move the actions outside of the state:

export const usePatientValidationStore = defineStore('patient-validation', {
  state: () => {
    return {
      validation: useStorage('patient-validation', {
        // True = valid entry
        firstName: true,
        lastName: true,
        dob: { day: true, month: true, year: true },
        patientId: true,
      }),
    }
  },

  actions: {
    async validateFLName() {
      ;/^[a-zA-Z]+$/.test
    },

    async validateDobDay() {
      ;/^(([0]?[1-9])|([1-2][0-9])|(3[01]))$/.test
    },

    async validateDobMonth() {
      ;/^(0?[1-9]|1[012])$/.test
    },

    async validateDobYear() {
      ;/^(19|20)\d{2}$/.test
    },
  },
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Shiinoya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants