The form API in core is great, but without contributed modules it lacks a bit of sweetness for html 5. This snippet shows you how:

$form['price'] = array(
    '#type' => 'textfield',
    '#attributes' => array(
        ' type' => 'number', // Note the space!
    '#title' => 'Price',
    '#required' => true,
    '#maxlength' => 3


Saved you some valuable time?

Donate and get more free time-saving code on this website in the future.