Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html pattern for a specific pattern

Tags:

html

regex

I have to try to write a pattern that accepts a character in the form of S0000/0000/0000 or P0000/0000/0000 Where 0 is any number

This is what I have a try

  <input class="form-control" type="text" pattern="^\d{5}/\d{4}/\d{4}$" name="index_no" required>

But that pattern it only accepts 5 digits / 4 digits / 4 digits what I need is S0000/0000/0000 OR P0000/0000/0000

like image 846
NgatungaEmily Avatar asked Dec 02 '25 11:12

NgatungaEmily


1 Answers

Use \ to escape special characters in html. Try this,

pattern="[SP]\d{4}\/\d{4}\/\d{4}"

You can test for correctness of regex expressions in this tester site

like image 90
vicki Avatar answered Dec 04 '25 00:12

vicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!