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 :
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/