HTML5表单输入模式货币格式 [英] HTML5 Form Input Pattern Currency Format

查看:373
本文介绍了HTML5表单输入模式货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTML5我有一个输入字段,应该根据输入的美元金额进行验证。目前我有以下标记:

Using HTML5 I have an input field that should validate against a dollar amount entered. Currently I have the following markup:

<input type="number" pattern="(\d{3})([\.])(\d{2})">

这适用于大于100.00且小于1,000.00的金额。我正在尝试编写模式(正则表达式)以接受不同的美元金额。也许超过100,000.00。这可能吗?

This works great for an amount that is greater than 100.00 and less than 1,000.00. I am trying to write the pattern (regex) to accept different dollar amounts. Maybe upwards of 100,000.00. Is this possible?

推荐答案

如果您想允许一个逗号分隔符,它将通过以下测试用例:

If you want to allow a comma delimiter which will pass the following test cases:

0,00  => true
0.00  => true
01,00 => true
01.00 => true
0.000 => false
0-01  => false

然后使用此:

then use this:

^\d+(\.|\,)\d{2}$

这篇关于HTML5表单输入模式货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆