문제

I simply need to be able to have a text field and validate if input is a decimal number like 100.00, 0.1, 10.6, etc.

I'm using Drupal 7.

Updated question to indicate 'programatic' solution (using Form API).

도움이 되었습니까?

해결책

You could use #element_validate option for your field and write your own validation function. Maybe you could use is_float() or is_number() in your validation function. So your code

$form['yourField'] = array(
....
'#element_validate'=>'myValidation'
);
....
function myValidation($element, &$form_state, $form){
  if (!is_float( $element['#value']) )){
    form_error($element, t('This field is not decimal.'));
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top