Vue - 메일박스 정규 검증

3380 단어
<el-form ref="emailForm" :model="emailForm" :rules="rules" label-width="120px">
    <el-form-item label=" " prop="mailAddress">
        <el-input placeholder=" " v-model="emailForm.mailAddress" @blur="sendEmail">el-input>
    el-form-item>
el-form>
    export default {
        name: 'email',
        data() {
            return {
                emailForm: {
                    mailAddress: null
                },
                rules: {
                    mailAddress: [{ required: true, message: ' ', trigger: 'change' }]
                }
            }
        },
        methods: {
            sendEmail: function() {
                var regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
                if (this.emailForm.mailAddress != '' && !regEmail.test(this.emailForm.mailAddress)) {
                    this.$message({
                        message: ' ',
                        type: 'error'
                    })
                    this.emailForm.mailAddress = ''
                }
            }
        }
    }

전재 대상:https://www.cnblogs.com/zltao/p/11007950.html

좋은 웹페이지 즐겨찾기