Vaska,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
<script>
$(function() {
$('a[dstype="consult_submit"]').click(function() {
$('#save_consult_form2').submit();
});
$.validator.addMethod('removeLink', function(value, element) {
let reg = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|(www\.)?[a-zA-Z0-9]+\.[^\s]{2,})/mig
let match = value.match(reg);
return !match || match.every(link => link.includes('javascript.ru'))
},
'Сообщение содержит запрещённые ссылки');
$('#save_consult_form2').validate({
errorPlacement: function(error, element) {
$('span[dstype="error_msg"]').append(error);
},
submitHandler: function(form) {
ds_ajaxpost('save_consult_form2');
},
onkeyup: false,
rules: {
content: {
required: true,
maxlength: 200,
removeLink: true
}
},
messages: {
content: {
required: 'Вы не указали вопрос',
maxlength: 'Вопрос не должен превышать 200 символов.'
}
}
});
});
</script>
</head>
<body>
<form method="post" id="save_consult_form2" action='goods/save_consult'>
<div class="comment-add"><textarea id="textfield3" name="content" type="text" rows="10" cols="70">
javascript.ru
https://cdnjs.cloudflare.com/ajax //для теста удалить эту строку
https://www.javascript.ru
</textarea></div>
<div class="comment-act">
<a href="JavaScript:void(0);" dstype="consult_submit" class="dss-btn">Отправить</a>
</div>
<span id="consultcharcount"></span> <span dstype="error_msg"></span>
</form>
</body>
</html>