Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set Last Six Digit Regex Patterns for HTML5 Text field

The validation I need for regex is to check only if the input has last six digit on the input.
Sample Accepted Input name are as follows:

  • Juan Dela Cruz 123456
  • Juan Dela Cruz | 123456
<form action="/action_page.php">
  <label for="employee">Employee Name:</label>
  <input type="text" id="employee" name="employee" pattern="([0-9]{6})$" title="Last Six Number"><br><br>
  <input type="submit">
</form>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try using this pattern instead:

.*([0-9]{6})$

That way, the entire value (including anything before the digits) matches. .* in RegEx matches anything.

  <input
    type="text"
    id="employee"
    name="employee"
    pattern=".*([0-9]{6})$"
    title="Last Six Number"
  >

JSFiddle: https://jsfiddle.net/ek9gmunh/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading