 
      
    JavaScript
    20
    Вклад в тег
    
      
      
    
  
  
newValue = newValue.replace(/[^а-яА-ЯЁё\s\-]/gi, ''); // дефис не был экранирован: он - тоже спецсимвол
    newValue = newValue.replace(/^[\s\-]+/g, '');
    newValue = newValue.replace(/[\s\-]+$/g, '');
    newValue = newValue.replace(/\s{2,}/g, ' '); // Заменялись все символы, а нужно от двух. Заменялось на пустую строку, а надо на пробел
    newValue = newValue.replace(/\-{2,}/g, '-'); // И то же самое для дефисовvar img1 = new Image();
img1.src = "img/background/1.png";
img1.onload = function() {
    ctx.drawImage(img1, 0, 0, x, y);
    var img2 = new Image();
    img2.src = "img/shadow/1.png";
    img2.onload = function() {
        ctx.drawImage(img2, 0, 0, x, y);
    }
}<div style="position: relative;">
<canvas id="layer1" width="100" height="100"
style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
<canvas id="layer2" width="100" height="100"
style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>