FormTestPatternForm.php in Drupal 8
File
core/modules/system/tests/modules/form_test/src/Form/FormTestPatternForm.php
View source
<?php
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class FormTestPatternForm extends FormBase {
public function getFormId() {
return 'form_test_pattern_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['textfield'] = [
'#type' => 'textfield',
'#title' => 'One digit followed by lowercase letters',
'#pattern' => '[0-9][a-z]+',
];
$form['tel'] = [
'#type' => 'tel',
'#title' => 'Everything except numbers',
'#pattern' => '[^\\d]*',
];
$form['password'] = [
'#type' => 'password',
'#title' => 'Password',
'#pattern' => '[01]+',
];
$form['url'] = [
'#type' => 'url',
'#title' => 'Client side validation',
'#description' => 'Just client side validation, using the #pattern attribute.',
'#attributes' => [
'pattern' => '.*foo.*',
],
'#pattern' => 'ignored',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}