function test(str){ var regex = /^[^_][A-Za-z]*[a-z0-9_]*$/ ; var ret = regex.test(str); if (ret == true) { alert('正确'); } else { alert('错误'); } }