Michael Harding
Michael Harding

Reputation: 67

Why is this Vue JS method function validEmail not definded

The function validEmail throws the following error. "error 'validEmail' is not defined"

<script>
export default {
  data() {
    return {
      accountEmail: "",
      accountEmailVerify: ""
    };
  },
  methods: {
    validateEmail() {
      validEmail(this.accountEmail);
    },
    validEmail(email) {
      var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      return re.test(email);
    }
  }
};
</script>

Upvotes: 0

Views: 46

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

You have to use this to refer to your component instance in order to access that method :

  methods: {
    validateEmail() {
      this.validEmail(this.accountEmail);
    },
    validEmail(email) {
      var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      return re.test(email);
    }
  }

Upvotes: 1

Related Questions