Reputation: 47
How can I make this kind of error message? I am building a login validation form.
Upvotes: 1
Views: 2209
Reputation: 407
You may try this as simple as it
<input type= "text" name= "name" pattern= "[0-9]" required="required">
You can also set Length
Upvotes: 1
Reputation: 4536
In addition:
You can use customValidity
api to create custom messages and will use the default tooltip provided by the browser.
DOCS: https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
Check bellow a simple example:
https://jsbin.com/popazajawu/2/edit?html,js,console,output
JS:
var inputs = document.querySelectorAll('input');
inputs.forEach(input => {
input.addEventListener('invalid', function(e) {
e.target.setCustomValidity("[CUSTOM MESSAGE] This field cannot be left blank")
})
input.addEventListener('input', function(e) {
e.target.setCustomValidity("");
})
})
Upvotes: 2