keto23
keto23

Reputation: 1207

Alphabetic Regex in HTML5

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:

Not accepted:

(Only alphabetic characters are accepted.)

Upvotes: 2

Views: 9992

Answers (3)

Jim Thomas
Jim Thomas

Reputation: 1658

Some nice examples: http://html5pattern.com/

In your case I would use:

[a-zA-Z]+

Upvotes: 5

Imp
Imp

Reputation: 8609

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.

Upvotes: 1

Adi
Adi

Reputation: 5169

pattern="[A-Za-z ]"

to allow only alphabetic characters and spaces

Upvotes: 0

Related Questions