手機號驗證Regex+Demo(親測完畢)

來源:互聯網
上載者:User

標籤:col   return   dem   put   fun   inpu   正則   tle   內容   

以下為本人親測過的驗證手機號格式的demo,需要的小夥伴拿走不謝~
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>

<!--這裡換成你自己的jquery地址-->
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<style type="text/css">
#phone_msg{
color: red;
font-size: 12px;
}
</style>
</head>
<body>
  <input type="text" id="phonenumber"/>
  <button>點擊跳轉</button>
  <p id="phone_msg"></p>
  <script type="text/javascript">
  $("button").click(function(){
  // 擷取輸入框
  var phoneInput = $("#phonenumber");
  // 擷取輸入框內容
  var phonenumber = $("#phonenumber").val();

  // 驗證手機號碼格式
  function isPoneAvailable(phoneInput){
  var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
  if (!myreg.test(phonenumber)) {
  $("#phone_msg").html("請輸入正確的手機號格式");
  return false;
  } else {
  $("#phone_msg").html("驗證成功,此條可不顯示");
  return true;
  }
  }
  isPoneAvailable();
  })
  </script>
</body>
</html>

手機號驗證Regex+Demo(親測完畢)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.