js检查首字符是否是英文字符

// / <summary>
//
/ 检查首字符是否是英文字符
//
/ </summary>
//
/ <param name="control">要验证的控件</param>
//
/ <param name="message">弹出信息</param>
//
/ <returns>true|false</returns>
function  IsEnChar(control,message)
{
    
if (control == null )
        
return   false ;
    
    
var  str = control.value;
    
if (str.charCodeAt( 0 ) >= 97   &&  str.charCodeAt( 0 ) <= 122 )
        
return   true ;
    
if (str.charCodeAt( 0 ) >= 65   &&  str.charCodeAt( 0 ) <= 90 )
        
return   true ;
        
    
if (message  != ''   &&  message  != null )
        alert(message);
    
else
        alert(
' 请输入指定格式 ' );
    
return   false ;
}

 

当然用正则表达式验证比较简单,大家可以写一下。在此省略......

你可能感兴趣的:(js)