[Vuejs]-Validating an email in native script code

0👍

You should use export default inside the script section and add } at the end of validEmail method and missing }, before validEmail method, you should also a the data object as follows :

<template>
    <Page>
        <ActionBar title="authentication" />
        <StackLayout id="registervalidate" class="registervalidate">
            <TextField v-model="youremail" class="youremail"></TextField>
            <TextField v-model="yourpassword" class="yourpassword">
            </TextField>
            <Button text="submit" @tap="onSubmit" />
        </StackLayout>
    </Page>
</template>

<script>
    export default {
        data() {
            return {
                yourmail: "",
                yourpassword: ""
            };
        },
        methods: {
            onSubmit: function() {
                if (!this.youremail) {} else if (!this.validEmail(this
                        .youremail)) {
                    //CHECK IF EMAIL IS VALID

                    return;
                }
                if (!this.yourpassword) {
                    return;
                } else {
                    return;
                }
            },
            validEmail: function(email) {
                // valid 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>

check this playground

Leave a comment