Vue检测密码复杂度方法

发布时间 2023-12-28 13:43:12作者: 刘俊涛的博客

Vue检测密码复杂度方法

<!-- 检测密码复杂度方法 -->
<template>
    <div>
    <input type="password" v-model="password" @input="checkPasswordComplexity">
    <div v-if="complexityMessage">{{ complexityMessage }}</div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            password: '',
            complexityMessage: ''
        };
    },
    methods: {
        checkPasswordComplexity() {
            const complexityRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
            if (complexityRegex.test(this.password)) {
                this.complexityMessage = '密码强度:强';
            } else if (this.password.length >= 6) {
                this.complexityMessage = '密码强度:中等';
            } else {
                this.complexityMessage = '密码强度:弱';
            }
        }
    }
};
</script>




欢迎关注公-众-号【TaonyDaily】、留言、评论,一起学习。

公众号

Don’t reinvent the wheel, library code is there to help.

文章来源:刘俊涛的博客


若有帮助到您,欢迎点赞、转发、支持,您的支持是对我坚持最好的肯定(_)