Numeric field type in Form API
$form['my_element'] = array(
    '#type' =&gt; 'textfield',
    '#attributes' =&gt; array(
        ' type' =&gt; 'number', // insert space before attribute name :)
    ),
    '#title' =&gt; 'My number',
    '#required' =&gt; true,
    '#maxlength' =&gt; 3
);