【问题标题】:Html pattern text input validation ng-pattern="/^-?[0-99]+(.[0-99]{0,2})?$/"Html 模式文本输入验证 ng-pattern="/^-?[0-99]+(.[0-99]{0,2})?$/"
【发布时间】:2018-07-01 08:20:44
【问题描述】:
<input type="text" ng-model="price" name="price_field" ng-pattern="/^-?[0-99]+(.[0-99]{0,2})?$/" required>

如果文本框值以 .(dot) 开头,则应附加 0(Zero) 例如:.50 => 结果也应为 0.50 如果是 5. 应该是 5.0

【问题讨论】:

    标签: javascript jquery angularjs html ng-pattern


    【解决方案1】:

    ng-pattern="/^-?([0-9]{0,2})+(.[0-9]{0,2})?$/" 使用这种允许 .5和 5. 你必须有某种解决方案来处理后端 .ng 模式中的这个数字,不能将 .5 转换为 0.5。您可以使用数字功能来实现这一点。

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      • 2021-08-10
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      相关资源
      最近更新 更多