The work of the common JS form verification code (including examples) _ form effects

Source: Internet
Author: User
Copy Code code as follows:



////----------------Author Teng-------------


//Verify is empty


function Check_blank (obj, obj_name) {


if (obj.value!= ") {


return true;


}else{


Alert (Obj_name + "cannot be filled in empty!") ");


obj.value = "";


return false;


}


}





//filter length of input characters


function Check_str_len (name,obj,maxlength) {


obj.value=obj.value.replace (^\s*) | ( \s*$)/g, "");


var newvalue = obj.value.replace (/[^\x00-\xff]/g, "* *");


var length11 = newvalue.length;


if (length11>maxlength) {

The length of the
alert (name+) cannot exceed the "+maxlength+" character! ");


obj.value= "";


Obj.focus ();


}


}





//verification can only be digital


function CheckNumber (obj) {


var reg =/^[0-9]+$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (' can only enter numbers! ');


obj.value = "";


Obj.focus ();


return false;


}


}





//Verify the range of the number size





function Check_num_value (obj_name,obj,minvalue,maxvalue) {


var reg =/^[0-9]+$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (obj_name+ ' can only enter numbers! ');


obj.value = "";


Obj.focus ();


return false;


}else if (minvalue>obj.value| | Obj.value>maxvalue) {

The range of
alert (obj_name+ "+minvalue+"-"+maxvalue+");


obj.value= "";


Obj.focus ();


return false;


}





}





//verification can only be letters and numbers


function Checkzmornum (zmnum) {


var zmnumreg=/^[0-9a-za-z]*$/;


if (zmnum.value!= "" &&!zmnumreg.test (Zmnum.value)) {


alert ("Enter only letters or numbers, please re-enter");


zmnum.value= "";


Zmnum.focus ();


return false;


}


}





//Verify double precision digital


function check_double (obj,obj_name) {


var reg =/^[0-9]+ (\.[ 0-9]+)? $/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (obj_name+ ' must be filled with a valid double-precision number ');


obj.value = "";


Obj.focus ();


return false;


}


}








//check box select all


function Checkboxs_all (obj,cname) {


var checkboxs = Document.getelementsbyname (cName);


for (Var i=0;i<checkboxs.length;i++) {


checkboxs[i].checked = obj.checked;


}


}








Verifying ZIP code


function Check_youbian (obj) {


var reg=/^\d{6}$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (' ZIP code format input Error! ');


obj.value = "";


Obj.focus ();


return false;


}


}





//Verify Mailbox Format


function Check_email (obj) {


var reg =/^[a-za-z0-9_-]+ (\. [a-za-z0-9_-]) +) *@[a-za-z0-9_-]+[.] [A-za-z0-9_-]+ ([.] [a-za-z0-9_-]+) *$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


Obj.select ();


alert (' e-mail format input Error! ');


obj.value = "";


Obj.focus ();


return false;


}


}





/* Verify fixed phone number


0\d{2,3} represents the area code


[0\+]\d{2,3} represents the international area code


\d{7,8} represents a 7-8-digit number (representing a phone number)


correct format: Area code-Phone number-extension number (all write | write phone number only)


*/





function Check_phone (obj) {


var reg=/^ ([0\+]\d{2,3}-)? ( 0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (' Phone number format input Error! ');


obj.value = "";


Obj.focus ();


return false;


}


}





//verification of mobile phone number (check 13,15,18 the beginning of the mobile phone number! )


function Check_telephone (obj) {


var reg=/^[1][358]\d{9}$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (' Mobile number format input Error! ');


obj.value = "";


Obj.focus ();


return false;


}


}





//Verification of Chinese


function Ischinese (obj,obj_name) {


var reg=/^[\u0391-\uffe5]+$/;


if (obj.value!= "" &&!reg.test (Obj.value)) {


alert (obj_name+ ' must enter Chinese! ');


obj.value = "";


Obj.focus ();


return false;


}


}





//Determine if IE browser





function Checkisie () {


if (-[1,]) {


alert ("This is not IE browser!") ");


}else{


alert ("This is IE browser!") ");


}


}





//Verify that the URL is correct


function Check_isurl (obj) {








}





//Check time size (compared with current time)


function Checkdate (obj,obj_name) {


var obj_value=obj.value.replace (/-/g, "/");//substitution character, into standard format (test format: ' 2009-12-10 ')


//Var obj_value=obj.value.replace ("-", "/");//substitution character, into standard format (check format: ' 2010-12-10 11:12 ')


var date1=new Date (Date.parse (Obj_value));


var date2=new date ();/Take today's Day


if (date1>date2) {


alert (obj_name+) cannot be greater than the current time! ");


return false;


}


}


copyright©2010-2012 com.zljy.teng.js////


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.