我有一個PHP腳本,用於驗證表單。目前它只允許數字/數字。我試圖用幾種方法修改它,但它要麼出錯或得到500錯誤。我只想添加$和。在提交中。修改PHP驗證腳本以允許使用現金標誌和小數
這裏是工作的腳本,僅驗證號碼:
class Quform_Filter_Digits implements Quform_Filter_Interface
{
/**
* Whether to allow white space characters; off by default
* @var boolean
*/
protected $_allowWhiteSpace = false;
/**
* Class constructor
*
* @param array $options
*/
public function __construct($options = null)
{
if (is_array($options)) {
if (array_key_exists('allowWhiteSpace', $options)) {
$this->setAllowWhiteSpace($options['allowWhiteSpace']);
}
}
}
/**
* Filter everything from the given value except digits
*
* @param string $value The value to filter
* @return string The filtered value
*/
public function filter($value)
{
$whiteSpace = $this->_allowWhiteSpace ? '\s' : '';
$pattern = '/[^0-9' . $whiteSpace .']/';
return preg_replace($pattern, '', (string) $value);
}
/**
* Whether or not to allow white space
*
* @param boolean $flag
* @return Quform_Filter_Digits
*/
public function setAllowWhiteSpace($flag)
{
$this->_allowWhiteSpace = (bool) $flag;
return $this;
}
/**
* Is white space allowed?
*
* @return boolean
*/
public function getAllowWhiteSpace()
{
return $this->_allowWhiteSpace;
}
}
@ jeroen我只是想讓該領域能夠驗證金錢。允許$ 00.00 –
@jeroen對不起,他們在我提交時出於維護原因而關閉了,當他們回來時輸入消失了,我很快開始複製錯誤的文件。然後當我幾分鐘前點擊問題時,他們以某種方式得到了正確的草稿。但我只是更新了 –