var str = "12345";

if(str.search(/^\d{5}$/) == 0) alert ("la stringa e` OK");
else alert("stringa non valida");

Ciao
Michele