货币(欧元)的正则表达式 [英] regex for currency (euro)
本文介绍了货币(欧元)的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用此代码对值进行验证.(来自这个网站的正则表达式)
i am trying this code for make a validation for a value. (regex from this site)
更新:
现在我有
$value1=250;
$value2=10000;
if (!preg_match("/^(([^0]{1})([0-9])*|(0{1}))(\,\d{2}){0,1}€?$/", $form['salary']) || (!$form['salary'])>$value1."€" && (!$form['salary'])<$value2."€" ){
echo ("invalido");
return false;
}
else
echo ("valido");
return true;
代码运行良好,但可以接受 20€,所以现在的问题不是正则表达式,而是比较 200€ 或 1000€ 之类的值.
the code works well, but 20€ is accepted, so the problem now is not the regex, but compare values like 200€ or 1000€.
这可能是错误的
(!$form['salary'])>$value1."€"
例如一些输入值:
200€
200
200.5
200.50€
limits - 250€ to 10000€
谢谢
推荐答案
下面这段代码解决了我的问题:
This code below solved my problem:
if (!preg_match("/^(([^0]{1})([0-9])*|(0{1}))(\,\d{2}){0,1}€?$/", $form['salary'])) {
echo "invalid";
return false;
} else {
$value1 = 400;
$value2 = 10000;
$salary = $form['salary'];
$salary = preg_replace('/[€]/i', '', $salary);
if($salary < $value1 || $salary > $value2) {
echo "bad values";
return false;
} else {
echo "valid";
return true;
}
}
这篇关于货币(欧元)的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文