zoukankan      html  css  js  c++  java
  • uni-app中对输入框的判断与提示(密码格式为6-12位,必须有大小写字母和数字组成)

    如图:

     

     

     vue

    <view class="input-item">
                        <view class="old">
                            <view class="icon">
                                <image src="../../static/icons/new-password.png" mode=""></image>
                            </view>
                            <view class="input">
                                <input type="password" v-if="isShow2" :placeholder="i18n.newPassword" placeholder-style="color:#c2c2c2" data-type="0"
                                 @blur="hideNewPass" :value="newPassword" maxlength="16" />
                                <input type="text" v-else :placeholder="i18n.newPassword" placeholder-style="color:#c2c2c2" data-type="0" @blur="newPass"
                                 :value="newPassword" maxlength="16" />
                            </view>
                            <view class="see">
                                <image :src="isShow2?'../../static/icons/not-show.png':'../../static/icons/show-words.png'" @tap="showNewPsd"
                                 mode="aspectFit" style="40rpx;height:40rpx"></image>
                            </view>
                        </view>
                        <!-- 错误提示 -->
                        <view class="error" v-if="errorTips==1">
                            <text class="error-icon">!</text>
                            <text class="error-text">{{i18n.newPasswordTips}}</text>
                        </view>
                    </view>
    data() {
                return {
    
                    isShow2: true,
                    inputType2: "password",
                    newPassword: "",
                    
                    errorTips: 0,
                    
                };
            },
    methods: {
    
                //输入新密码
                newPass(e) {
                    this.newPassword = e.detail.value;
                    
                    // 密码格式为6-12位,必须有大小写字母和数字组成 
                    var newPass = this.newPassword;
                    var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
    
                    if (!reg.test(newPass) || newPass.length < 6 || newPass.length > 12) {
                        this.setData({
                            errorTips: 1,
                            // newPassword: "",
                        })
                        // this.newPassword = ""
                    } else {
                        this.setData({
                            errorTips: 0,
                            // newPassword: newPass,
                        })
                        // this.newPassword = newPass
                        // 赋值为空失败
                    }
                    // this.$apply();
                },
                
                //输入新密码
                hideNewPass(e) {
                    this.newPassword = e.detail.value;
                    var newPass = this.newPassword;
                    var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
                    
                    if (!reg.test(newPass) || newPass.length < 6 || newPass.length > 12) {
                        this.setData({
                            errorTips: 1,
                        })
                        // this.newPassword = ""
                    } else {
                        this.setData({
                            errorTips: 0,
                            // newPassword: newPass,
                        })
                        // this.newPassword = newPass
                    }
                    // this.$apply();
                },
                // 点击小眼睛图标切换
                showNewPsd() {
                    if (this.isShow2) {
                        this.isShow2 = false;
                        this.inputType2 = "text";
                        // this.$apply();
                    } else {
                        this.isShow2 = true;
                        this.inputType2 = "password";
                        // this.$apply();
                    }
                },
                }

    css

    /* 错误提示区 */
    .error{
        font-size: 28rpx;
        padding-left: 40rpx;
        padding-top: 10rpx;
    }
    .error .error-icon{
        display: inline-block;
         30rpx;
        height: 30rpx;
        line-height: 30rpx;
        text-align: center;
        border-radius: 20rpx;
        background-color: #fe3535;
        color: #FFFFFF;
        margin-right: 20rpx;
    }
    .error .error-text{
        color: #E43130;
    }
  • 相关阅读:
    pipelinewise 学习二 创建一个简单的pipeline
    pipelinewise 学习一 docker方式安装
    Supercharging your ETL with Airflow and Singer
    ubuntu中使用 alien安装rpm包
    PipelineWise illustrates the power of Singer
    pipelinewise 基于singer 指南的的数据pipeline 工具
    关于singer elt 的几篇很不错的文章
    npkill 一个方便的npm 包清理工具
    kuma docker-compose 环境试用
    kuma 学习四 策略
  • 原文地址:https://www.cnblogs.com/yoona-lin/p/13705646.html
Copyright © 2011-2022 走看看