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

  • Home
  • SEARCH
  • 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 6320089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:54:43+00:00 2026-05-24T15:54:43+00:00

I want to validate my registration form but i have default values for every

  • 0

I want to validate my registration form but i have default values for every text input. Tried all possible ways with jquery validate plugin. It’s hard to understand how to use it (I’m newbie to js) What i want to do, is ignore the default values and validate form. My form looks like that

<from id="reg">
<input class="part1 default" type="text" name="fname" id="fname" value="Adınız (First Name)"/>
<input  class="part1 default"  type="text" name="mname"  value="Atanızın adı (Middle name)"/>
</form>

I’m using this piece of code for this form

var defaultValues = {
    'fname': 'Adınız',
    'mname': 'Atanızın adı',
    'lname': 'Soyadınız',
    'phone': 'Telefon',
    'email': 'Email',
    'pwd':'Şifrə',
    'region':'Rayon',
    'school':'Məktəb',
    'login':'Istifadəçi adı',
    'class':'Sinif',
    'subject':'Fənnin adını daxil edin',
    'dob': 'Date of Birth'
};
$('input').live('focus', function() {
    var el = $(this);
    if (el.hasClass('default')) {
        el.removeClass('default').val('');
    }
    if (el.attr('id') === 'dob') {
        $(this).mask('99.99.9999', {placeholder:' '});
    }
});

$('input').live('blur', function() {
    var el = $(this);
    var name = el.attr('name');

    // Really we only want to do anything if the field is *empty*
    if (el.val().match(/^[\s\.]*$/)) {

        // To get our default style back, we'll re-add the classname
        el.addClass('default');

        // Unmask the 'dob' field
        if (name == 'dob') {
            el.unmask();
        }

        // And finally repopulate the field with its default value
        el.val(defaultValues[name]);
    }
});

/*validation*/
 $('#reg').submit(function (event) 
    {
        if ($('#fname').val() == defaultValues['Adınız'] || $.trim($('#pwd').val()) == '')
        {
            alert('Please enter the name!');
            return false;
        }
        else
        {
            if ($('#fname').val().length < 2)
            {
                alert('The name must be >2 letters!');
                return false;
            }
        }
    });

The last part as you see is the validation. I have a feq questions about it

  1. Lets say we wrote if’s for all possible cases. What if allright and
    we want to continue submitting process? Do i need to write new if
    for it and end this if with “return true?”
  2. I used this piece of code but it always gives me the same error
    message “Please enter a password!” even if all input fields are
    filled. How can we modify this code to alert the array of errors?
    for example if my pass is wrong type and name field unfilled the script will
    show 2 errors at once. I thought about logic too: For example every
    time when some case is true then it pushes to array the error
    message and when it finishes checking all cases, shows the error
    array. But can’t realise it.
    How to validate email field, and date of birth field (looks like “19.16.2010”)?
  • 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-05-24T15:54:43+00:00Added an answer on May 24, 2026 at 3:54 pm

    Instead of placing the default value in a “value” attribute, why not set it as the “placeholder”.

    <input type="text" name="fname" id="fname" placeholder="Adınız (First Name)"/>
    

    Then you can just do regular validation…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate my form using jquery but it doesn't have an ID
I have built a registration form where I want to validate fields in it.
I want to validate the input of a jTextField and also have a default
I want to validate a registration form that accepts an email address in the
I have currently a website which lets every user register, but I want to
I want to validate the value a user enters in a text box, so
I want to validate a condition before doing the next step, but only raise
If I want to validate that a text box contains an integer greater than
I have some MET data I want to validate which would look something like
I'm using a basic registration form with AJAX, but the form is not connecting

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.