$(document).ready(function() {
$('.class-email').blur(function() {
if($(this).val() != '') {
var pattern = /^([a-z0-9_\.-])+@[a-z0-9-]+\.([a-z]{2,4}\.)?[a-z]{2,4}$/i;
if(pattern.test($(this).val())){
$(this).removeClass('error');
$('#valid').text('');
} else {
$(this).addClass('error');
$('#valid').text('The field is required.');
}
}
});
});
const inputSelector = '#icons_care';
const checkboxSelector = '.check_care';
const checkboxCheckedSelector = `${checkboxSelector}:checked`;
const dataAttr = 'icon';
const separator = ', ';
$(document).on('change', checkboxSelector, () => {
$(inputSelector).val($(checkboxCheckedSelector)
.get()
.map(n => $(n).data(dataAttr))
.join(separator)
);
});
// или
document.addEventListener('change', e => {
if (e.target.matches(checkboxSelector)) {
const input = document.querySelector(inputSelector);
const cb = document.querySelectorAll(checkboxCheckedSelector);
input.value = Array.from(cb, n => n.dataset[dataAttr]).join(separator);
}
});
ngrok http --host-header=dev.site.ru 80
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
color = color.indexOf("rgb") !== -1 ? rgb2hex(color) : color;