最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regex which allows 3 digit before precision and 2 digits after precision - Stack Overflow

programmeradmin0浏览0评论

I have written a Regex which will take only integers but I need to rewrite this regex to only allow 3 digit before precision and 2 digits after precision

How to do that?

I have written a Regex which will take only integers but I need to rewrite this regex to only allow 3 digit before precision and 2 digits after precision

How to do that?

Share Improve this question edited Oct 24, 2012 at 10:33 Lee Taylor 7,99416 gold badges37 silver badges53 bronze badges asked Oct 24, 2012 at 10:27 PeteEngineerPeteEngineer 1134 silver badges14 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

If it must always have 3 digits, a decimal point, and 2 digits, e.g., 412.88, then:

/^\d{3}\.\d{2}$/

If it can be up to 3 digits before and up to 2 after (possibly no decimal point at all) then maybe something like:

/^\d{1,3}(\.\d{1,2})?$/

In c#

@"^\d{3}\.\d{2}$"

//in c# we need to use verbatim string `@""` to treat escape sequences as normal literals instead of giving it a special meaning..

In javascript

/^\d{3}\.\d{2}$/

发布评论

评论列表(0)

  1. 暂无评论