Reputation: 538
I try to find a solution for this HTML5 form validation scenario:
I have an input field, wher the user needs to enter his full name like "John J. Jones"
<input id="test" name="test" type="text"
placeholder="Please insert your full name"
pattern="this is where I need some help please"
required="required"
title="Please insert your full name as per your registration form">
I would like the pattern to validate, if "somewhere" in the input field the string 'Jones' (or 'jones') has been entered. It could be in the beginning, somewhere in the middle or at the end, can be entered in all lowercase, upper and lowercase combination or upper case only ...
So valid inputs would be:
"J.J. Jones"
"j.j.jones"
"Jones, John"
"jones, john"
"John Jones III."
"j.jones III."
All is ok, as long as "jones" is somewhere in the string entered.
Thank you!
Upvotes: 0
Views: 273
Reputation: 1246
The HTML5 pattern is always case sensitive. You could try to do it manually. I'm not a regex expert, but I guess this should do the job, despite being kind of ugly:
pattern=".*[j|J][o|O][n|N][e|E][s|S].*"
or I guess this would work too (plus, it looks a bit better):
pattern=".*[jJ][oO][nN][eE][sS].*"
Upvotes: 1
Reputation: 332
You could do something like this:
pattern=".*((j|J)(o|O)(n|N)(e|E)(s|S))+.*"
Upvotes: 1