Home > Web Front-end > JS Tutorial > body text

js code to verify whether mobile phone number and phone number are legal_javascript skills

WBOY
Release: 2016-05-16 15:48:16
Original
904 people have browsed it

This article mainly introduces the js code to verify whether the mobile phone number and phone number are legal. Mobile phone numbers and phone numbers are required on some websites. In order to improve the user experience, legality verification is generally required. The specific code is as follows: function Checkreg(){ .....

function Checkreg(){
  //验证电话号码手机号码,包含  ,  号段
  if(document.form.phone.value==""&&document.form.UserMobile.value==""){
   alert("电话和手机号码至少选填一项!");
   document.form.phone.focus();
   return false;
  }
  if(document.form.phone.value != ""){
   var phone=document.form.phone.value;
   var p =/^(([ \+]\d{ , }-)?( \d{ , })-)?(\d{ , })(-(\d{ ,}))?$/;
   var me=false;
   if(p .test(phone)){ 
    me=true;
   }
   if(!me){
    document.form.phone.value='';
    alert('对不起,您输入的电话号码有错误。区号和电话号码之间请用-分割');
    document.form.phone.focus();
    return false;
   }
  }
  if(document.form.UserMobile.value != ""){
   var mobile=document.form.UserMobile.value;
   var reg =/^ \d{ , }$/;
   var reg =/^  \d{ , }$/;
   var reg =/^  \d{ , }$/;
   var reg =/^ \d{ , }$/;
   var my=false;
   if(reg .test(mobile))my=true;
   if(reg .test(mobile))my=true;
   if(reg .test(mobile))my=true;
   if(reg .test(mobile))my=true;
   if(!my){
    document.form.UserMobile.value='';
    alert('对不起,您输入的手机或小灵通号码有错误。');
    document.form.UserMobile.focus();
    return false;
   }
   return true;
  }
 }
Copy after login

The above code is all about using js to verify whether the mobile phone number and phone number are legal. I hope you like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template