Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

html - HTML5 phone number validation with pattern

I'm using HTML5 form validation to validate phone numbers from India.

Phone numbers from India are 10 digits long, and start with 7, 8, or 9.

For example:

  1. 7878787878
  2. 9898989898
  3. 8678678878

These phone numbers are valid, but

  1. 1212121212
  2. 3434545464
  3. 6545432322

are invalid.

Suggest a pattern that can detect valid India phone numbers.

So far, my pattern is [0-9]{10}, but it doesn't check if the first digit is 7, 8, or 9.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How about

<input type="text" pattern="[789][0-9]{9}">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...