<script type="text/javascript">
$(function () {
$("#txtEmail").blur(function () {
$.ajax({
type: "post",
url: "reg.ashx?email=" + $.trim($("#txtEmail").val()) + "&d=" + (+new Date()),
success: function (data) {
var vCount = parseInt(data);
if (vCount == ) {
alert("邮箱可以使用");
}
else {
alert("邮箱已经被占用");
}
}
});
}); $("#checkpwd").blur(function () {
return CheckPwd();
});
}); function CheckPwd()
{
var bCheck = true;
if ($.trim($("#pwd").val()) != $.trim($("#checkpwd").val()))
{
alert("两次密码输入不一致");
bCheck = false;
}
return bCheck;
} </script>

reg.ashx代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace WebT1.Ti.html2
{
/// <summary>
/// reg 的摘要说明
/// </summary>
public class reg : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
if (context.Request["email"] != null)
{
string strEmail = context.Request["email"];
List<UserModel> lstUser = DataService.GetUserList();
var v = lstUser.Where(p => p.Email == strEmail);
int iCount = ;
if (v.Count() > )
{
iCount = ;
}
context.Response.ContentType = "text/plain";
context.Response.Write(iCount.ToString());
} } public bool IsReusable
{
get
{
return false;
}
}
} public class DataService
{
/// <summary>
/// 模拟已注册用户数据
/// </summary>
public static List<UserModel> GetUserList()
{
var list = new List<UserModel>();
list.Add(new UserModel() { Email = "t1@demo.com" });
list.Add(new UserModel() { Email = "t2@demo.com" });
list.Add(new UserModel() { Email = "t3@demo.com" });
list.Add(new UserModel() { Email = "t4@demo.com" });
list.Add(new UserModel() { Email = "t5@demo.com" });
return list;
}
} public class UserModel
{
public string Email { get; set; }
}
}

ajax邮箱、用户名唯一性验证的更多相关文章

  1. laravel 修改时邮箱字段唯一性验证时忽略指定 ID

  2. 从零开始学 Web 之 Ajax(四)接口文档,验证用户名唯一性案例

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  3. 基于jQuery实现的Ajax 验证用户名唯一性

    基于jQuery实现的Ajax 验证用户名唯一性 前端jsp页面代码 <tr> <th><span class="requiredField"> ...

  4. JQuery+Ajax实现唯一性验证、正则

    //唯一性验证 public function Only(){ //实例化模型层 $model = new User(); $res = $model->Only(); echo $res; } ...

  5. 案例1.用Ajax实现用户名的校验

    用Ajax实现用户名的校验 java的验证类 public class UserDao { public boolean checkUserName(String name) { //这里的name是 ...

  6. 使用原生Ajax进行用户名重复的检验

    title: 使用原生Ajax进行用户名重复的检验(一) date: 2019-01-21 17:35:15 tags: [JavaScript,Ajax] --- Ajax的复习 距离刚开始学aja ...

  7. 验证控件,解决用于ajax提交前的验证,不是submit提交的验证

    //解决ajax提交前的验证问题,主要用于onclick事件时对某一区域中(可以是form,div,table中的等)控件的验证.(function ($) { var v; //Create a n ...

  8. PHP+Ajax 异步通讯注册验证

    HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  9. asp.net ajax检查用户名是否存在代码

    原文  asp.net ajax检查用户名是否存在代码 用户注册时,我们经常需要检查用户名是否存在,本文就是实现无刷新验证用户名 打开开发环境VS 2005,新建项目(或打开现有项目),新建一个Web ...

随机推荐

  1. 使用idea工具开发webservice

    在idea开发工具中使用axis2插件创建集成webservice的web项目: 一.创建java项目                  二.添加webservices支持 在红线框2处选择要使用的w ...

  2. Python 并发编程:PoolExecutor 篇

    个人笔记,如有疏漏,还请指正. 使用多线程(threading)和多进程(multiprocessing)完成常规的并发需求,在启动的时候 start.join 等步骤不能省,复杂的需要还要用 1-2 ...

  3. 正则匹配java多行注释

    类似: /** * This method was generated by MyBatis Generator. * This method returns the value of the dat ...

  4. iterator 的设计原则和traits

    iterator我前面写过是作为algorithm和container之间的一个桥梁,algorithm进程操作的时候向iterator进行提问,iterator并对提问进行了回答,其中主要就是回答5 ...

  5. about !dbgprint to analyze BSOD dump file.

    基本规则: 只有debug mode enable的机器,产生的dump file才会保存dbgprint的buffer. 默认!dbgprint的buffer size是4k. 增加buffer s ...

  6. vue2.0实现页面刷新时某个input获得focus

    通过自定义指令:

  7. linux cfs 负载均衡

    确定新的负载的时候,代码中给出的公式是: (old×(2^i-1) + new))/2^i 整理下来是: old + (new-old)/2^i i的范围是[1, 4],也就是说,i的层级越高,那么n ...

  8. 变量可以通过into赋值

  9. BZOJ4602 SDOI2016齿轮(搜索)

    dfs一遍给每个齿轮随便标个值看是否矛盾就行了. #include<iostream> #include<cstdio> #include<cmath> #incl ...

  10. HDU——1394 Minimum Inversion Number

    Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...