jQuery验证表单远程规则,成功消息

前端之家收集整理的这篇文章主要介绍了jQuery验证表单远程规则,成功消息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 jquery验证我的注册表单,它工作得很好,但我遇到了问题.我检查电子邮件是否存在,如果电子邮件确实存在,我收到错误消息.现在我想编辑这个,所以,如果电子邮件是免费使用的话.错误消息将更改为:此电子邮件可以免费使用.
  1. $(document).ready(function(){
  2. $("#registratieform").validate({
  3. rules: {
  4. email: {
  5. required: true,email: true,remote: {
  6. url: "includes/check_email.PHP",type: "post",complete: function(data){
  7. if( data.responseText == "false" ) {
  8. alert("Free");
  9. }
  10. }
  11. },},messages: {
  12. email: {
  13. required: "This field is required",email: "Please enter a valid email address",remote: jQuery.format("{0} is already taken")
  14. },});
  15. });

警报有效,但此消息必须出现在错误所在的标签中.这可能吗?

解决方法

@Ruub:
远程消息应该是一个函数,而远程消息在规则中只是一个用于检查的URL
例:
  1. $("#registratieform").validate({
  2. rules: {
  3. email: {
  4. required: true,remote: "includes/check_email.PHP"
  5. }
  6. },messages: {
  7. email: {
  8. required: "This field is required",remote: function() { return $.validator.format("{0} is already taken",$("#email").val()) }
  9. },});

在服务器端(includes / check_email.PHP):

  1. if (!isValidEmail($_REQUEST['email'])) {
  2. echo "false";
  3. exit;
  4. }

猜你在找的jQuery相关文章