<!DOCTYPE html>
<html><head> <title>validate</title> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <style type="text/css"> *{margin: 0; padding: 0; list-style: none; outline: none;} #form_id{ padding: 100px;} .vidata{ font-size: 13px; color: #f00;} </style></head><body><form id='form_id'> <ul> <li>电话:<input class="input-phone" type="text"><span class='vidata'>*</span></li> </ul></form><script type="text/javascript">//$('.input-phone').focus(function(){alert(1)});
var oE={ Input:$('.input-phone'), Vidata:$('.vidata') };oE.Input.keyup(function(){
var oVal=oE.Input.val().substr(0,1);
if(oVal==1)
{ var Ex=/^1[3|4|5|8]\d{9}$/; if(!Ex.test(oE.Input.val())) { oE.Vidata.text('*你输入的手机电话号码有误!') }else{ oE.Vidata.text('*') };}else if(oVal==0){
//var Ex=/^\d{12}$/; //var Ex=/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;px:051-0793-3281156-001 var Ex=/^((0\d{2,3})-)?(\d{7,8})$/;//ps:0793-3281156if(!Ex.test(oE.Input.val()))
{ oE.Vidata.text('*你输入的座机电话号码有误!') }else{ oE.Vidata.text('*') }; }else{ oE.Vidata.text('*你输入的号码有误!') }});
</script>
</body></html>