Design goal: Build a universal web validation plug-in based on jQuery framework...
Design requirements: 1. Need beautiful css style and small icon decoration...
2. Based on jQuery framework.. .
3. Call the .net Web service to achieve asynchronous interaction with the database...
Solution: 1. First, let’s design three classes to display the visual appearance of the Web to the user. Perception. They are
.msg_warning{font-family:Arial,Helvetica,sans-serif,simsun; background:#e7f7ff url(register/MsgWarning.gif) no-repeat;border:solid 1px #6cf;color:#333 ;padding:0 0 0 36px !important;width:220px; margin-left:20px;}
.msg_error{font-family:Arial,Helvetica,sans-serif,simsun;background:#fff3ef url(register/MsgError .jpg) no-repeat;border:solid 1px #ff6610;color:#333;padding:0 0 0 36px !important;width:220px; margin-left:20px;}
.msg_ok{font- family:Arial,Helvetica,sans-serif,simsun;background:#e7ffe7 url(register/MsgOk.gif) no-repeat;border:solid 1px #95e895;color:#333;padding:0 0 0 36px !important;width :220px; margin-left:20px;}
They are different styles for verification errors, verification warnings and correct verification...
2. Place the image in the corresponding position, as shown in the style, including MsgWarning.gif, MsgError.jpg, and MsgOk.gif are three small pictures corresponding to .msg_warning; .msg_error; .msg_ok;
3. Start writing the script
(1), //Remove the null value
String.prototype.trim = function()
{
var x = this;
x = x.replace(/^s*(.*)/, "$1");
return x;
}
This function is used to remove empty positions (trim) in the text box...
(2). Write two arrays to store prompt statements and styles when triggering verification...
var ErrorWords = ['Correct! ', 'Cannot be empty! ', 'E-mail address length cannot exceed 50 characters! ', 'Please enter the correct email format! ',"The password must be greater than 6 and less than 16!","The key does not match!",'The company name cannot exceed 50 digits! ',"Neither the area code nor the number is empty!","The area code is 4 digits!","The number is 7-10 digits!","The QQ number is 5-12 digits!",'The address length is not More than 50 people! ','The name must be in Chinese within 10 characters! ','The mobile phone number is 11 digits! ','The zip code is 6 digits! ','The username is between 3-15 digits! ','The domain name format is wrong! ','This username has been registered! ','This email address has been registered! ']
var ErrorClass = ['msg_ok', 'msg_warning', 'msg_warning', 'msg_error', 'msg_warning', 'msg_error', 'msg_warning', 'msg_warning', 'msg_error','msg_error ','msg_error','msg_error','msg_error','msg_error','msg_error','msg_error','msg_error','msg_error','msg_error']
(3), start writing Various validation types, I wrote all I could think of...
;(function($){
//as long as
jQuery.fn.extend({
"checkEmail":function() //
{
$(this).blur(function(){
var check;
var email=$(this).val().toLowerCase();
var strSuffix = " cc|com|edu|gov|int|net|org|biz|info|pro|name|coop|al|dz|ar|ae|aw|om|az|eg|et|ie|ee|ad| ao|ai|ag|at|au|mo|bb|pg|bs|pk|py|ps|bh|pa|br|by|bm|bg|mp|bj|be|is|pr|ba|pl| bo|bz|bw|bt|bf|bi|bv|kp|gq|dk|de|tl|tp|tg|dm|do|ru|ec|er|fr|fo|pf|gf|tf|va| ph|fj|fi|cv|fk|gm|cg|cd|co|cr|gg|gd|gl|ge|cu|gp|gu|gy|kz|ht|kr|nl|an|hm|hn| ki|dj|kg|gn|gw|ca|gh|ga|kh|cz|zw|cm|qa|ky|km|ci|kw|cc|hr|ke|ck|lv|ls|la|lb| lt|lr|ly|li|re|lu|rw|ro|mg|im|mv|mt|mw|my|ml|mk|mh|mq|yt|mu|mr|us|um|as|vi| mn|ms|bd|pe|fm|mm|md|ma|mc|mz|mx|nr|np|ni|ne|ng|nu|no|nf|na|za|aq|gs|eu|pw| pn|pt|jp|se|ch|sv|ws|yu|sl|sn|cy|sc|sa|cx|st|sh|kn|lc|sm|pm|vc|lk|sk|si|sj| sz|sd|sr|sb|so|tj|tw|th|tz|to|tc|tt|t|tv|tr|tm|tk|wf|vu|gt|ve|bn|ug|ua|uy| uz|es|eh|gr|hk|sg|nc|nz|hu|sy|jm|ac|ye|iq|ir|il|it|in|id|uk|vg|io|jo|vn| zm|je|td|gi|cl|cf|cn";
var regu = "^[a-z0-9][_a-z0-9-]*([.][_a-z0-9- ] )*@([a-z0-9-_] [.]) (" strSuffix ")$";
var re = new RegExp(regu);
if(email.trim()=='') check=1;
else if(email.length > 50) check=2;
else if(email.search(re) == -1) check=3;
else { check=0;}
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
========================== ============================
//Folder Activities
jQuery.fn.extend({
" checkCode":function()
{
$(this).blur(function(){
var check;
var pwd=$(this).val();
var path = /^[a-zA-Z0-9_]{6,16}$/;
if(pwd.trim()=='') check=1
else if(!path.test(); pwd)) check=4;
else check=0;
$(this).next().remove("span"
$(this).after("" ErrorWords[check] "");
})
}
}) >jQuery.fn.extend({
"checkCode2":function(pwd)
{
$(this).blur(function(){
var check;
var pwd2=$ (this).val();
if(pwd2.trim()=='') check=1
else if(pwd2!=$(pwd).val()) check=5; 🎜>else check=0
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
=============== ========================= ========
//If you want to run
jQuery.fn.extend({
"checkCPName":function()
{
$(this). blur(function(){
var check;
var CPName=$(this).val();
if(CPName.trim()=='') check=1;
else if(CPName.length>50) check=6;
else check=0;
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
=======================
jQuery.fn.extend({
"checkTel":function()
{
$(this).blur(🎜>{ var check;
var names=$(this).attr("name"); $("input[name='" names "']").eq(0).val( ); /;
var path2= /^[0-9]{7,10}$/
if(check1.trim() == ''|| check2.trim()=='') check. =7;
else if(!path1.test(check1)) check=8;
else if(!path2.test(check2)) check=9; $("input[name='" names "']").eq(1).next().remove("span"
$("input[name='" names "']"); .eq(1).after("" ErrorWords[check] ""
})
}
); })
=================================
//闭包QQ /MSN核对
jQuery.fn.extend({
"checkQQ":function()
{
$(this).blur(function(){
var check;
var CPQQ=$(this).val();
var path= /^[0-9]{5,12}$/;
if(CPQQ.trim()=='') check=1;
else if(!path.test(CPQQ)) check=10;
else check=0;
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
========================== ========================= ====
//
jQuery.fn.extend({
"checkAdd":function()
{
$(this).blur(function() {
var CPAdd=$(this).val();
if(CPAdd.trim()=='') check=1
else if(CPAdd.length> ;50) check=11;
else check=0;
$(this).next().remove("span"
$(this).after("" ErrorWords[check] "");
})
}
})
============================================== ===========================================
//Closure The user's real name check uses the function to return the program result
jQuery.fn.extend({
"checkRealName":function()
{
var check;
$(this).blur(function (){
var realName=$(this).val();
var reg = /^[u4e00-u9fa5]{1,10}$/gi;
if(realName.trim() =='') check=1;
else if(!reg.test(realName)) check=12;
else check=0;
$(this).next().remove(" span");
$(this).after("" ErrorWords[check] "");
return check;
})
}
})
================================== ================================================
//Closure mobile phone number check
jQuery.fn.extend({
"checkPhone":function()
{
$(this).blur(function(){
var check;
var telephone=$(this).val();
var reg=/^[0-9]{11}$/;
if(telephone.trim()=='' ) check=1;
else if(!reg.test(telephone)) check=13;
else check=0;
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
============================================== ================================================
//Closure zip code check
jQuery.fn.extend({
"checkPCode":function()
{
$(this).blur(function(){
var check ;
var PCode=$(this).val();
var reg=/^[0-9]{6}$/;
if(PCode=='') check=1;
else if(!reg.test(PCode)) check=14;
else check=0;
$(this).next().remove("span");
$( this).after("" ErrorWords[check] "");
})
}
})
================================================== ==========================================
// Closure username check
jQuery.fn.extend({
"checkUserName":function()
{
$(this).blur(function(){
var check;
var UserName=$(this).val();
if(UserName=='') check=1;
else if(UserName.length15) check= 15;
else check=0;
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
})
}
})
=========== ================================================== ===================
//Closure domain name verification
jQuery.fn.extend({
"checkSite":function( )
{
$(this).blur(function(){
var check;
var WebSite=$(this).val();
var reg= /http(s )?://([w-] .) [w-] (/[w- ./?%&=]*)?/;
if(WebSite=='') check=1;
else if(!reg.test(WebSite)) check=16;
else check=0;
$(this).next().remove("span");
$(this) .after("" ErrorWords[check] "");
})
}
})
================================================== ====================================
//Verify whether the user name exists in the database (call WebService method)
jQuery.fn.extend({
"nameAjax":function(LName,Lfun)
{
$(this).blur(function(){
var check;
var thisid=$(this).attr("id");
var logname=$(this).val();
if(logname=='')
{
check=1;
$("#" thisid).next().remove("span");
$("#" thisid).after("" ErrorWords[check] "");
}
else if(logname.length15)
{
check=15;
$(this).next().remove("span");
$(this).after("" ErrorWords[check] "");
}
else
{
$.ajax({
type: "POST",
contentType: "application/ json;utf-8",
url: "./WebService.asmx/" LName,
data:"{" Lfun ":'" logname "'}",
dataType: 'json',
anysc:false,
success:function(data)
{ if(data.d) check=17;
else check=0;
$("#" thisid).next ().remove("span");
$("#" thisid).after("" ErrorWords[check] " ");
}
})
}
})
}
})
Corresponding Web service method:
///
///Here we check whether the login name exists, here we are lazy and use random verification
///
///
///
[WebMethod]
public bool checkLogoName(string lognames)
{
Random r = new Random();
int i = r.Next(1, 10000);
if (i % 2 == 0) return true;
return false;
}
============================================== ===========================================
//Verify user Whether the mailbox is in the database (method of calling Web service)
jQuery.fn.extend({
"emailAjax":function(Lemail,Lfun)
{
$(this).blur(function (){
var check;
var thisid=$(this).attr("id");
var email=$(this).val().toLowerCase();
var strSuffix = "cc|com|edu|gov|int|net|org|biz|info|pro|name|coop|al|dz|af|ar|ae|aw|om|az|eg|et|ie|ee |ad|ao|ai|ag|at|au|mo|bb|pg|bs|pk|py|ps|bh|pa|br|by|bm|bg|mp|bj|be|is|pr|ba |pl|bo|bz|bw|bt|bf|bi|bv|kp|gq|dk|de|tl|tp|tg|dm|do|ru|ec|er|fr|fo|pf|gf|tf |va|ph|fj|fi|cv|fk|gm|cg|cd|co|cr|gg|gd|gl|ge|cu|gp|gu|gy|kz|ht|kr|nl|an|hm |hn|ki|dj|kg|gn|gw|ca|gh|ga|kh|cz|zw|cm|qa|ky|km|ci|kw|cc|hr|ke|ck|lv|ls|la |lb|lt|lr|ly|li|re|lu|rw|ro|mg|im|mv|mt|mw|my|ml|mk|mh|mq|yt|mu|mr|us|um|as |vi|mn|ms|bd|pe|fm|mm|md|ma|mc|mz|mx|nr|np|ni|ne|ng|nu|no|nf|na|za|aq|gs|eu |pw|pn|pt|jp|se|ch|sv|ws|yu|sl|sn|cy|sc|sa|cx|st|sh|kn|lc|sm|pm|vc|lk|sk|si |sj|sz|sd|sr|sb|so|tj|tw|th|tz|to|tc|tt|tn|tv|tr|tm|tk|wf|vu|gt|ve|bn|ug|ua |uy|uz|es|eh|gr|hk|sg|nc|nz|hu|sy|jm|am|ac|ye|iq|ir|il|it|in|id|uk|vg|io|jo |vn|zm|je|td|gi|cl|cf|cn";
var regu = "^[a-z0-9][_a-z0-9-]*([.][_a-z0 -9-] )*@([a-z0-9-_] [.]) (" strSuffix ")$";
var re = new RegExp(regu);
if(email.trim( )=='') { check=1;$(this).next().remove("span"); $(this).after(" " ErrorWords[check] ""); }
else if(email.length > 50) { check=2; $(this).next().remove("span"); $ (this).after("" ErrorWords[check] ""); }
else if(email.search(re) = = -1) { check=3; $(this).next().remove("span"); $(this).after("" ErrorWords [check] ""); }
else
{
$.ajax({
type: "POST",
contentType: "application/json;utf- 8",
url: "./WebService.asmx/" Lemail,
data:"{" Lfun ":'" email "'}",
dataType: 'json',
anysc :false,
success:function(data)
{ if(data.d) check=18;
else check=0;
$("#" thisid).next().remove ("span");
$("#" thisid).after("" ErrorWords[check] "");
}
})
}
})
}
})
Corresponding Web service method:
///
/// Check whether the mailbox exists, here Lazy and use random verification
///
///
///
[WebMethod]
public bool checkLogEmail(string logemails)
{
Random r = new Random();
int i = r.Next(1, 10000);
if (i % 2 == 0) return true;
return false;
}
====================== ================================================== =============
//Final submission
jQuery.fn.extend({
"toReg":function(num) //Please note the nun here, enable Write as many numbers as there are verifications, because I enabled all the above 15 verifications...
{
$(this).click(function(){
var erolen=$(".msg_error ").length;
var warlen=$(".msg_warning").length;
var oklen=$(".msg_ok").length;
if(oklen==num)
{ alert("Verification passed..."); }
else alert("Error: " erolen ", Warning: " warlen ", Pass: " oklen ", please fill in the information completely! ");
})
}
})
})(jQuery);
====================== ================================================== ======================
4. Introduce scripts into the Web page
5. HTML source code of the Web page
User login name verification:
Email verification:< ;input type="text" id="Emails"/>
Password verification: < ;br />
Change the password:
Company Name check:
Telephone: Area code:
-
Fax: Area code:
-
User QQ:
Company address:
User’s real name:
Mobile phone number verification:
Postcode verification:
Domain name verification:
Verification:
//This is the end
Source code download address
http://xiazai.jb51.net/201010/yuanma/jqueryRegister.rar

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
