Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First name validation using html 5 pattern

I have this code

 echo '<input type="text" maxlength="32" name="first_name" pattern="[A-Za-z]" value="'.$_SESSION['user_first_name'].'" required>';

Even if I put something correct it says 'PLease match the requested format'

The data is 'testme' which is correct but it's not passing the validation.

like image 306
Raj Avatar asked Aug 07 '14 13:08

Raj


2 Answers

You need to specify how long the pattern should be. pattern="[A-Za-z]{1,32}"

echo '<input type="text" maxlength="32" name="first_name" pattern="[A-Za-z]{1,32}" value="'.$_SESSION['user_first_name'].'" required>';
like image 180
user2687506 Avatar answered Oct 27 '22 00:10

user2687506


pattern="[A-Za-z ]{1,32}" <- Use space in the first name pattern.

like image 29
Vinoth Avatar answered Oct 27 '22 01:10

Vinoth