最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Alphabetic Regex in HTML5 - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 5

Some 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

发布评论

评论列表(0)

  1. 暂无评论