I'm really new to regex but I need to find a way to add a filter to a HTML5 form:
<input type="text" required="true" name="firstname" pattern="WHAT DO I PUT HERE">
Could anyone help me with what to put in the pattern attribute, for example
Accepted:
John
Frank
Not accepted:
Ke$ha
B0B
(Only alphabetic characters are accepted.)
I'm really new to regex but I need to find a way to add a filter to a HTML5 form:
<input type="text" required="true" name="firstname" pattern="WHAT DO I PUT HERE">
Could anyone help me with what to put in the pattern attribute, for example
Accepted:
John
Frank
Not accepted:
Ke$ha
B0B
(Only alphabetic characters are accepted.)
Share Improve this question edited May 5, 2012 at 17:26 vyegorov 22.9k7 gold badges61 silver badges76 bronze badges asked May 5, 2012 at 2:01 keto23keto23 1,2071 gold badge11 silver badges16 bronze badges 2- if this post is solved, can you kindly check the answer that solved it. – Joseph Commented May 5, 2012 at 2:13
- I tried before but it said please wait 3 minutes, I have now though – keto23 Commented May 5, 2012 at 2:20
3 Answers
Reset to default 5Some nice examples: http://html5pattern./
In your case I would use:
[a-zA-Z]+
You aren't too specific, but I'll assume you want to rule out nonalphabetic characters.
The pattern for non-empty alphabetic-only word is
[a-zA-Z]+
where a-z
stands for the range of lowercase letters, A-Z
for the range of uppercase letter. [a-zA-Z]
then means any letter and +
means at least one.
pattern="[A-Za-z ]"
to allow only alphabetic characters and spaces