0

Input Field: how can i customize the error message in pattern which is used in input field in html 5.

currently message show "Please enter a value matching the pattern" this massage show after customize "Only Numeric Number Allowed"

<?= $this->Form->input('mobile', 
['pattern'=>"^(?!0)[0-9]{10}$",
'label' => false, 'id' => '',
 'class' => 'form-control reg_mobile_input',
'required' => true,'id'=>'',
'placeholder'=>'without initail zero',]); 
?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Md.Shahjalal
  • 393
  • 1
  • 6
  • 21
  • **http://stackoverflow.com/questions/10361460/how-can-i-change-or-remove-html5-form-validation-default-error-messages** – ndm Jun 01 '16 at 21:55

1 Answers1

0

You can set most attributes by just passing them to the form helper so the following should work:

<?= $this->Form->input('mobile', [
    'class' => 'form-control reg_mobile_input',
    'label' => false,
    'oninvalid' => 'setCustomValidity(\'Without trailing zero\')',
    'pattern' => "^(?!0)[0-9]{10}$",
    'placeholder'=>'without initail zero'
    'required' => true,
]); ?>

See MDN docs on setCustomValidity for more on custom HTML error messages.

cjquinn
  • 739
  • 3
  • 14