在我的php中,我使用preg_match來驗證輸入文本。用於貨幣值(例如5000或5000.00)的文本框或可以接受空白。preg_match only nummber,允許空格和貨幣格式
$pattrn="/^[0-9]{10}$/";
通過使用它可以驗證數字只。 如何使用preg_match過濾此輸入?
在我的php中,我使用preg_match來驗證輸入文本。用於貨幣值(例如5000或5000.00)的文本框或可以接受空白。preg_match only nummber,允許空格和貨幣格式
$pattrn="/^[0-9]{10}$/";
通過使用它可以驗證數字只。 如何使用preg_match過濾此輸入?
您可以使用:
$pattrn = "/^(?:\d+(?:\.\d+)?)?$/";
說明:
/^ # Assert position at the beginning of the string
(?: # Begin a non-capturing group
\d+ # Match one or more digits from 0-9
(?: # Begin a non-capturing group
\.\d+ # Match a dot (.) followed by one more digits from 0-9
)? # Make the capturing group optional
)? # Make the capturing group optional
$/ # Assert positon at the end of the string
你應該使用$ pattrn =「^((?:\ d \ d {3}。 ?| \ d {1,3})\ d {1,3},\ d {1,2})$「;
在這裏看到的樣品preg_match() or similar function for checking currency
可以接受; 6000.00,6000和空 –
檢查了這一點http://stackoverflow.com/questions/10371476/preg-match-decimals-not-working –
嘗試'$ pattrn =「/ ^(?:\ d +( ???:\ \ d +))$ /「'。 –
嗨,有陌生人@AmalMurali ;-) –