js的:

<script type="text/javascript"> 
function checkMobile(){ 
    var sMobile = document.mobileform.mobile.value 
    if(!(/^[1][3,4,5,8][0-9]{9}$/.test(sMobile))){ 
        alert("不是完整的11位手机号或者正确的手机号前七位"); 
        document.mobileform.mobile.focus(); 
        return false; 
    } 
} 
</script> 
<form action="#" name="mobileform" method="post" onSubmit="return checkMobile();"> 
<INPUT name="mobile" size="40" maxLength="11"> 
<INPUT name="action" type="hidden" value=mobile> 
<INPUT class=bdtj name=B1 type=submit value="查 询"> 
</FORM>

 

java的:

/**
		 * 手机号验证
		 * 
		 * @param  str
		 * @return 验证通过返回true
		 */
		public static boolean isMobile(String str) { 
			Pattern p = null;
			Matcher m = null;
			boolean b = false; 
			p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号
			m = p.matcher(str);
			b = m.matches(); 
			return b;
		}
		/**
		 * 电话号码验证
		 * 
		 * @param  str
		 * @return 验证通过返回true
		 */
		public static boolean isPhone(String str) { 
			Pattern p1 = null,p2 = null;
			Matcher m = null;
			boolean b = false;  
			p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$");  // 验证带区号的
			p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$");         // 验证没有区号的
			if(str.length() >9)
			{	m = p1.matcher(str);
	 		    b = m.matches();  
			}else{
				m = p2.matcher(str);
	 			b = m.matches(); 
			}  
			return b;
		}