Variante 1
let str = '123456';
let regex = /^(\d{6})?$/;
// RegEx testen
// Besp: String muss aus 6 Zahlen bestehen
if (regex.test(str))
{
console.log('match');
}
else
{
console.log('no match');
}
Variante 2
let str = '123456';
// RegEx testen
// Besp: String muss aus 6 Zahlen bestehen
if (/^(\d{6})?$/.test(str))
{
console.log('match');
}
else
{
console.log('no match');
}