Front-desk JS verification

Source: Internet
Author: User

Self summary

1. Set text box to enter only numbers

Onkeyup= "This.value=this.value.replace (/[^\d]/g,") "//Replace onkeypress=" Keypressnumber () "Onafterpaste=" this.value=  This.value.replace (/[^\d]/g, ') "onpaste=" return false; " Prohibit paste

function Keypressnumber () {//can only enter numbers
var keycode = Event.keycode;
if ((keycode >= && keycode <= 57))
{
Event.returnvalue = true;
} else {
Event.returnvalue = false;
}
}

2. Only letters and numbers can be entered

Onkeypress= "Keypresspwd ()" onpaste= "return false;"

function Keypresspwd () {
var keycode = Event.keycode;
if ((keycode >= && keycode <= 57) | | (KeyCode >= && keycode <= 122) | | (KeyCode >= && keycode <= 90))
{
Event.returnvalue = true;
} else {
Event.returnvalue = false;
}
}

3//determines whether the character entered is: a-z,a-z,0-9 maximum 12 bits, allowed to be empty

function Isstringa_z0_9 (str)
{
if (str.length!=0) {
reg=/^[a-za-z0-9]{1,12}$/;
if (!reg.test (str)) {
return false;
}
return true;
}
return true;
}

4//determine No. 400 number
function Is400phone (str) {
   if (str.length==0) {
    return true;
  }  
      reg=/^400\d{7}$/;    
       if (!reg.test (str)) {   
             return false;
     }   
      return true;
 } 

5//determines the landline number
function Istel (obj) {
        var str = obj.value;
        if (str.length = = 0) {
             return true;
       }
        reg =/^ (0[0-9]{2,3}\-)? ([2-9][0-9]{6,7}) + (\-[0-9]{1,4})? $/;
        if (!reg.test (str)) {
             return false;
       }
        return true;
   }

6 //determine the phone number
function Isphone (str) {
   if (str.length==0) {
    return true;
  }  
      reg=/^ (\d{3}-\d{8}$|^\d{4}-\d{7}$) | ( (13[0-9]|14[0-9]|15[0-9]|18[0-9]) \d{8}$)/;    
      if (! Reg.test (str)) {   
            return False
     }   
      return true;
 }   

7//Determines whether the character entered is: Kanji, a-z,a-z, number
function isstring (str)     
 {       
         if (str.length!=0) {      
          Reg=/^[0-9a-za-z\u4e00-\u9fa5]{1,}$/gi;   
          if (!reg.test (str)) {   
              return false;
         }   
           return true;
        }   
          return true;
 }

8//Determines whether the characters entered are compound mailbox format
function isemail (str)     
 {       
         if (str.length!=0) {     
          reg=/^[^\[email protected]][email protected][^ \[email protected]]+\. [a-z]+$/;
          if (!reg.test (str)) {   
               return false;
         }   
           return true;
        }   
          return true;
 }  

9//determine if the phone number includes landline and mobile phone
function Isphoneormobile (str) {
if (str.length==0) {
return true;
}
REG1 =/^ (\d{3}-\d{8}$|^\d{4}-\d{7}$) | ((13[0-9]|14[0-9]|15[0-9]|18[0-9]) \d{8}$)/;
REG2 =/^ (0[0-9]{2,3}\-)? ([2-9][0-9]{6,7}) + (\-[0-9]{1,4})? $/;
if (!reg1.test (str) &&!reg2.test (str)) {
return false;
}
return true;
}

10//Judge QQ

function isqq (str)
{
if (str.length!=0) {
reg=/^[1-9]{1}[0-9]{4,9}$/;
if (!reg.test (str)) {
return false;
}
return true;
}
return true;
}

11

Front-desk JS verification

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.