【问题标题】:4 digit password PIN validation for input filed in AngularJs Cordova android applicaitonAngularJs Cordova android应用程序中输入字段的4位密码PIN验证
【发布时间】:2016-05-13 05:52:01
【问题描述】:

我正在使用 AngularJs 为 android 创建一个 Cordova 应用程序。我的应用程序中有一个输入 PIN 码页面。我需要为我的输入字段添加以下验证:

  1. 输入应该是数字。(需要显示数字键盘)。
  2. 最大长度应为 4。
  3. 字段类型应为密码。

我试过<input type="password" maxLength="4" inputmode="numeric" pattern="[0-9]*"/>

在上面的代码中,最大长度验证正在工作,并将输入字段作为密码。但数字键盘或数字验证对我不起作用。

然后我尝试了<input type="number" min=1000 max="9999"/>

在上面的代码中,4 位验证正在工作并得到数字键盘。但这些值不受密码保护。

我在 android 中需要这个解决方案。请给我一个解决方案。

谢谢

【问题讨论】:

    标签: javascript android angularjs cordova validation


    【解决方案1】:

    我的答案来自herehere 的帖子。

    请在下面找到我得到的解决方案:

    <input id="password" oninput="maxLengthCheck(this)" maxlength="4" type = "number"  placeholder="Enter Pin" name="password" required /> 
    
    
    <script>
      function maxLengthCheck(object) {
        if (object.value.length > object.maxLength)
            object.value = object.value.slice(0, object.maxLength)
        }
    </script>
    
    <style>
        input[type=number] {
            -webkit-text-security: disc;
        }
    </style>
    

    谢谢

    【讨论】:

    • 非常好..非常感谢
    猜你喜欢
    • 1970-01-01
    • 2015-11-23
    • 2022-11-26
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 2013-06-27
    • 1970-01-01
    相关资源
    最近更新 更多