Home > Back-end >  Is there a pattern to limit the first four numbers in my input box?
Is there a pattern to limit the first four numbers in my input box?

Time:01-04

The result should be like this, 2018-00130. The first 4 numbers are year, I wanted to limit the year to 2010 up to 2022.

I have tried to use the input type = number but I can't limit the numbers since I need the dash sign. My pattern for now is just like this, pattern="[^a-zA-Z]*" maxlength = "10".

CodePudding user response:

This is a very basic RegEx and quite simple to implement.

Here's the code:

<form>
  <label for="code">Code:</label><br>
  <input type="text" id="code" name="code" pattern="20(1[0-9]|2[0-2])-[0-9]{5}" maxlength="10" required>
  <input type="submit" value="Submit">
</form>

CodePudding user response:

Try this:

<input type="text" maxlength="4" style="width:50px;"> - <input type="text" maxlength="6">

  •  Tags:  
  • html
  • Related