Form validation: text has to be a number
Drupal already has a helper for this, in the shape of the element_validate_number() validation callback:

function MYMODULE_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['number']['#element_validate'][] = 'element_validate_number';
}


You can also use element_validate_integer() or element_validate_integer_positive if either of those make more sense for your use case.