Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery validation .NET4
jQuery.validator.addMethod("mail", function (value, element) {
var f = 0;
jQuery.ajax({
type: "get",
url: "Master/chkmail",
async: true,
cache: false,
data: { mail: function () { return $("#email").val(); } },
dataType: "json",
success: function (data) { if (data == true) { f = 1; } else { f = 0; }
},
error: function () { alert(arguments[1]); }
})
return f < 0 ? false : true;
});
 
Mastercontroller:
public JsonResult chkmail(string mail)
{
JsonResult result = new JsonResult();
BLL.Member bll = bll = new MvcBBS.BLL.Member();
if (bll.emailExists(mail))
{
 
result.Data = true;
}
else
{
result.Data = false;
}
return result;
}
Please help me,thanks a lot
Posted 16-Dec-12 15:17pm
gavinv421
Comments
Christian Graus at 16-Dec-12 20:39pm
   
why do you use jQuery. instead of $. ? It makes your code hard to read compared to the accepted norm
Sergey Alexandrovich Kryukov at 6-Mar-13 15:23pm
   
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

data: { mail: function () { return $("#email").val(); } },
 
Does this even work ? Why not get the value and put it in to the data in another line of code ?
 
Have you debugged in Chrome ? What line has the error ?
  Permalink  
Comments
gavinv at 16-Dec-12 20:52pm
   
the chkmail can get the value from that code, i've checked it. I just test this in
IE9.The problem is when i run this set of code it just show me that "email" already exsited, maybe this prove that "success" can't get the json from "chkmail"
gavinv at 16-Dec-12 21:01pm
   
The validate code is :
$(document).ready(function () {
$("#regf").validate({
rules: {
 
username: { required: true
},
email:{required:true,email:true,mail:true},
password: { required: true }
},
messages: {
username: { required: '  input it!' },
email: { required: '  please input!', email: '  like this:a@a.com!', mail: '  already exsited!' },
password: { required: 'pealse input!' }
}
}
 
)
})

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100