简体   繁体   English

Codeigniter regex_match与金钱

[英]Codeigniter regex_match with money

I am using code igniters form_validation and I was wondering if there was away to validate money for a text box for an example allow 4 numbers and then a period and then 2 numbers. 我正在使用代码点火器form_validation,我想知道是否可以验证文本框的钱,例如允许输入4个数字,然后输入一个句点,然后输入2个数字。

This what I got so far 这是我到目前为止所得到的

regex_match[/^[0-9.]{0,7}+$/]

It works well, but I can enter a number like 100.000, is there anything I can do about it? 效果很好,但是我可以输入一个100.000的数字,对此我能做些什么吗?

To match exactly as you are requesting this would do it: 要完全匹配您的要求,可以这样做:

regex_match[/^\d{4}\.\d{2}$/] // allow 4 numbers only a period and then two numbers only

If you want to match UP TO 4 numbers so allow 1.00, 10.00, 100.00 but not more than 4 numbers before the decimal then use this: 如果要匹配最多4个数字,因此允许1.00、10.00、100.00,但小数点前不能超过4个数字,请使用以下命令:

regex_match[/^\d{1,4}\.\d{2}$/]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM