Answer the question
In order to leave comments, you need to log in
How can I prevent the form from submitting if there are not enough characters?
It is necessary that the form is not submitted if the input type="tel" is less than 15 characters.
Here's what's there:
<input type="tel" placeholder="+48 111-111-111" id="phone" name="phone" data-field="item" required>
<input id="but1" value="Zamówic" type="submit">
$(function () {
var inputName = $('[data-field="input-name"]');
$(document).on('input', '[data-field="item"]', function () {
var item = $(this);
$('#but1').on('click', function() {
if (item.val().length < 15) {
alert('< 15 символов');
}
});
});
});
Answer the question
In order to leave comments, you need to log in
$('#but1').on('click', function(event) {
if (item.val().length < 15) {
alert('< 15 символов');
event.preventDefault();
// event.stopPropagation(); <-- еще можно остановить клик, но так не советуется делать
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question