код который делает блок с ошибками
function showError(container, errorMessage) {
container.className = 'error';
var msgElem = document.createElement('span');
msgElem.className = "error-message";
msgElem.innerHTML = errorMessage;
container.appendChild(msgElem);
}
код который проводит валидацию
function validate(form) {
var validationFailed = false;
$(".valid-form input").each(function(){
if (!this.value) {
showError(this.parentNode, $(this).attr('title'), 'Filed cannot be empty');
validationFailed = true;
} else if (this.value.indexOf('\'') >= 0 || this.value.indexOf('"') >= 0) {
showError(this.parentNode, $(this).atrr('title'), 'Field cannot contain quotes');
validationFailed = true;
}
else {
resetError(this.parentNode);
}
});
return !validationFailed;
}
вот код который отвечает за проверку на скобки
else if (this.value.indexOf('\'') >= 0 || this.value.indexOf('"') >= 0) {
showError(this.parentNode, $(this).atrr('title'), 'Field cannot contain quotes');
validationFailed = true;
}
вот хтмл форма
<form action="" name="registration" id="myForm">
<div class="valid-form">
<label for="firstname">Имя</label>
<input type="text" name="firstname" title="Укажите ваше имя" placeholder="John"/>
</div>
</form>
как сделать что бы при вводе кавычек отображался другой title в ошибку а не этот с Укажите ваше имя?
Добавьте третий параметр в функцию showError.
<form action="" name="registration" id="myForm">
<div class="valid-form">
<label for="firstname">Имя</label>
<input type="text" name="firstname"
data-messageempty="Укажите ваше имя" data-messagequote="кавычка в вашем имени"/>
</div>
</form>
function validate(form) {
var validationFailed = false;
$(".valid-form input").each(function(){
if (!this.value) {
showError(this.parentNode, $(this).data('messageempty'), 'Filed cannot be empty');
validationFailed = true;
} else if (this.value.indexOf('\'') >= 0 || this.value.indexOf('"') >= 0) {
showError(this.parentNode, $(this).data('messagequote'), 'Field cannot contain quotes');
validationFailed = true;
} else {
resetError(this.parentNode);
}
});
return !validationFailed;
}
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости