in case regular expressions is not a must, wouldn't it be better to just ask the browser to decide using eval
?
function isValidVarName( name ) {
try {
// Update, previoulsy it was
// eval('(function() { var ' + name + '; })()');
Function('var ' + name);
} catch( e ) {
return false;
}
return true;
}
isValidVarName('my_var'); // true
isValidVarName('1'); // false