Eingabe muss eine Zahl enthalten

Ein Code-Snippet, wie man mit JS prüft, ob eine Eingabe eine Zahl enthält

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function validateStreet(e) {
    const streetNotice = document.getElementById('streetnotice');
    let currentvalue = e.value;
    let outputvalue = currentvalue.search(/\d/g);

    if (outputvalue === -1) {
        streetNotice.style.display = "block";
    } else {
        streetNotice.style.display = "none";
    }
}

Codepen

Erstellt mit Hugo
Theme Stack gestaltet von Jimmy