Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - HTML Form Validation - Check for Specific Characters

I'm using the Html5 pattern to validate my inputs on forms. I need to make sure an input has the following rules:

  1. A maximum and minimum of 8 characters
  2. The first 3 must be the specific letters wrx (lowercase)
  3. The last 5 must be numbers.

Eg. wrx12345

Can I even do this with pattern or do I need to use JavaScript?

question from:https://stackoverflow.com/questions/65882874/html-form-validation-check-for-specific-characters

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

1 Answer

0 votes
by (71.8m points)

I believe the regex pattern you are looking for is /^wrx[0-9]{5}$/. A visual representation of this here:

regex visual

And implemented in html:

<input name="example" pattern="^wrx[0-9]{5}$">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...