var val = number.value if (/^d{10}$/.test(val)) { // value is ok, use it } else { alert("Invalid number; must be ten digits") number.focus() return false }