function checkPhone(phone,phoneError){ var phone1 = $("#"+phone).val(); if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone1))){ // alert("手机号码有误,请重填"); $("#"+phoneError).show(); $("#"+phone).val(''); // $("#"+phone).focus(); }else{ $("#"+phoneError).hide(); } }
<span><input type="text" name="sendPhone3" onblur="checkPhone('sendPhone3','sendPhone3Error')" id="sendPhone3" ></span> <span class="hint2" id="sendPhone3Error"><img src=/pss_wrong.png' />"/>请注意为手机格式</span>