You can try with test()
function that returns true/false
var str='0123456789';
console.log(/^\d{10}$/.test(str));
OR with String#match()
function that returns null
if not matched
var str='0123456789';
console.log(str.match(/^\d{10}$/));
Note: Just use ^
and $
to match whole string.