Reputation: 191
I'm trying to make a custom pattern for my html input but have no idea how to do so!
The pattern I want: ABC-A0-01
So basically the first part has uppercase alphabets only, second part has uppercase with numeric values, and the last part is numeric only and is separated by a '-'
<input type="text" class="form-control txtsize" id="equi" placeholder="Insert equipment name e.g ABC-A0-12" data-ng-model="equipmentToAdd">
Upvotes: 0
Views: 36
Reputation: 14541
You could use the pattern
attribute with a RegEx such as this: pattern="[A-Z]{3}[-][A-Z]{1}[0-9]{1}[-][0-9]{2}"
.
Try inputting an invalid value, and hit submit. The browser will give an error with the message from title
property.
<form>
<input type="text" class="form-control txtsize" id="equi" placeholder="Insert equipment name e.g ABC-A0-12" data-ng-model="equipmentToAdd" pattern="[A-Z]{3}[-][A-Z]{1}[0-9]{1}[-][0-9]{2}" title="Insert equipment name e.g ABC-A0-12">
<button type="submit">Submit</button>
</form>
Upvotes: 3