Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:17:07+00:00 2026-06-07T09:17:07+00:00

A simple registration form has a field Preferred login id (username). As soon as

  • 0

A simple registration form has a field “Preferred login id (username)”. As soon as user enters email, I validate entered username (if it already exists or not) by comparing it with database values. For this I am doing server call using $.ajax method of jquery.

<script>
$('#txtPreferredLogin').focusout(function () {
            $.ajax({
                type: "POST",
                url: "../Login.aspx/CheckUserName",
                async: false,`enter code here`
                data: "{userName: '" + $('#txtPreferredLogin').val() + "' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    $('#valid').html("<img src='Images/waiting.gif' alt='Checking username!'>");
                    var delay = function () {
                        AjaxSucceeded(response);
                    };
                    setTimeout(delay, 500);
                },
                failure: function (response) {
                    alert(response.d);
                }
            });
        });

        function AjaxSucceeded(result) {
            if (result.d == true) {
                $('#valid').html("<img src='Images/2_Not.png' alt='Username taken!'>");
            }
            else {
                $('#valid').html("<img src='Images/1_available.png' alt='Username available!'>");
            }
        }

        $.validator.addMethod('notNone', function (value, element) {
            return (value != '0');
        });

        $(function () {
            $("#regi1").validate(
            {
                rules:
                {
                    ddlCity:
                      {
                          required: true,
                          notNone: true
                      },
                    txtDOB:
                      {
                          required: true,
                          dpDate: true
                      }
                },
                messages: {
                    ddlCity: "Please select city",
                    txtDOB: "Please enter a valid date (dd-mm-yyyy)"
                }
            });
        });

</script>

Server side code is

public bool getVal(string userName)
        {
            var query = from p in context.tblBasicDetails
                        where p.LoginId == userName.Trim()
                        select p;
            if (query.Any())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        [WebMethod]
        public static bool CheckUserName(string userName)
        {
            Login l = new Login();
            return (l.getVal(userName));
        }

Now when username is not available it shows message (image) that its unavailable. But I have Save button below these fields, on click of which whole form get validated i.e. it doesn’t postback page until all fields are valid except in case of username unavailability. Now I don’t want to do postback if username is unavailable. What changes i need to do in code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:17:10+00:00Added an answer on June 7, 2026 at 9:17 am

    As Riaz said remote validation is very helpful but in your case you are already checking username so you dont want to visit server again.

    jquery has .data function which you can use.

    function AjaxSucceeded(result) {
        if (result.d == true) {
            $('#valid').html("&lt;img src='Images/2_Not.png' alt='Username taken!'>");
            $("#txtPreferredLogin").data("available", false); //add data
        } else {
            $('#valid').html("&lt;img src='Images/1_available.png ' alt='        Username available!'>");
            $("#txtPreferredLogin").data("available", true); //add data
        }
    }
    
    //add validator
    $.validator.addMethod('
            available ', function(value, element) {
        return $(element).data("available");
    });
    
    
    
    $(function() {
        $("#regi1").validate({
            rules: {
                txtPreferredLogin: {
                    required: true,
                    available: true
                },
                ddlCity: {
                    required: true,
                    notNone: true
                },
                txtDOB: {
                    required: true,
                    dpDate: true
                }
            },
            messages: {
                ddlCity: "Please select city",
                txtDOB: "Please enter a valid date (dd-mm-yyyy)"
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple registration form. Once all information entered, user click submit button and
i am making a user registration form with validation.thats my simple form field. <tr>
I want to create a simple user registration form with First / Last name,
Can anyone give me some simple code to validate a registration form using ajax?
I will add a honeypot-field to the devise registration form (as a simple captcha).
I'm using the jQuery.validate plugin to validate inputs for my user registration form. I've
I have one simple User Registration form. It includes name, age, sex & city.
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
I have a simple registration page that validates if a user is already taken.
I did a simple rails form with two user inputs , name and email.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.