Using the remote function of jquery validation

后端 未结 8 679
逝去的感伤
逝去的感伤 2020-12-16 03:12

I\'m trying to figure out how I can turn this:

$(\'#username\').blur(function(){
    $.post(\'register/isUsernameAvailable\', 
           {\"username\":$(\'#         


        
8条回答
  •  一生所求
    2020-12-16 03:36

    Well I dunno bout your plugin concept specifically but I gather you want it to check to see with that plugin if the username is greater than 6 or less than 12. Which from your core example with jQuery without the plugin it would be as simple as adding one little if-else to the concept.

    $('#username').blur(function(){
        if($('#username').val().length < 6 || $('#username').val().length > 12)
        {
            alert('Username must be between 6 and 12 characters');
        }
        else
        {
           $.post('register/isUsernameAvailable', 
                  {"username":$('#username').val()}, 
                  function(data){
                      if(data.username == "found"){
                          alert('username already in use');
                      }
                  }, 'json');
        }
    });
    

提交回复
热议问题