JS Verify that the input is a mobile number

Source: Internet
Author: User
Tags trim

  Use JS to verify the input is a mobile phone number or phone number, here is a good example, interested friends can refer to the following

Code as follows:  code as follows: <script type= "Text/javascript" >  String.prototype.Trim = function () {  var m = This.mat CH (/^s* s+ (s+s+) *) s*$/);  return (M = = null)? ' ': m[1]; }  String.prototype.isMobile = function () {  return (/^ (?: 13d|15[89))-?d{5} (D{3}|*{3}). Test (this. Trim ()); }  String.prototype.isTel = function ()   { //"compatible Format: Country code (2 to 3 bits)-Zip code (2 to 3 digits)-Phone number (7 to 8 digits)-Extension number (3-bit) " //return (/^) ([0+]d{2,3}-)? ( 0d{2,3})? (d{7,8}) (-(D{3,}))? $/.test (this. Trim ()));  return (/^ ([0+]d{2,3}-)? 0d{2,3})-(d{7,8}) (-(D{3,})? $/.test (this. Trim ()); }  function Chkform () {  with (Document.form1) {  if (tel.value.isMobile () | | Tel.value.isTel ()) {  Tel.value = Tel.value.Trim ();  alert ("Your phone/mobile number is:" + tel.value);  return true;  }  Else {  alert ("Please enter the correct cell phone number or phone number nn for example: 13916752109 or 0712-3614072");  Tel.focus ();  return false; } } }  </script>  <form name= "Form1"Method= "POST" action= "" >  <input type= "Text" name= "tel" value= "13916752109" size= ""/>  <input Type= "button" value= "Test" onclick= "return Chkform ()"/>  </form>   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.