0

actually I am confused about how to validate every single field of my date

<div class='p-0 m-0'>
  <label class='form-label QstFonts mx-5'>What is your date of birth?</label>
  <div class='mt-5 mb-2 d-flex align-items-center justify-content-center'>
    <input
      asp-for='HLApplication.Day'
      id='txtbox1'
      onkeyup="GnderTextboxsValidation('txtbox1','txtbox2','txtbox3','genderButton')"
      class='input-text col-lg-3 col-2 m-lg-2 m-2 py-4'
      requird
      maxlength='2'
      placeholder='DD'
    />
    <span> / </span>
    <input
      asp-for='HLApplication.Month'
      id='txtbox2'
      onkeyup="GnderTextboxsValidation('txtbox1','txtbox2','txtbox3','genderButton')"
      class='input-text col-lg-3 col-2 m-lg-2 m-2 py-4'
      requird
      maxlength='2'
      placeholder='MM'
    />
    <span> / </span>
    <input
      asp-for='HLApplication.Year'
      id='txtbox3'
      onkeyup="GnderTextboxsValidation('txtbox1','txtbox2','txtbox3','genderButton')"
      class='input-text col-lg-3 col-2 m-lg-2 m-2 py-4'
      requird
      maxlength='4'
      placeholder='YYYY'
    />
  </div>
  <div class='row p-0 m-0'>
    <div class='col-12  p-0 m-0'>
      <div class='p-0 mx-5 row m-auto d-flex'>
        <button
          id='genderButton'
          disabled
          type='button'
          onclick="HairLossClick('37','38'); SubmitForm();"
          class='btn btn-primary my-lg-4 my-1 py-3 h-25 m-auto'
        >
          Continue
        </button>
      </div>
    </div>
  </div>
</div>;

the following code is for disable and enable btn on basis of textboxs

function GnderTextboxsValidation(txtbox1, txtbox2, txtbox3, Button) {
    if (document.getElementById(txtbox1).value === "" ||
        document.getElementById(txtbox2).value === "" ||
        document.getElementById(txtbox3).value === "") {
        document.getElementById(Button).disabled = true;
    } else {
        document.getElementById(Button).disabled = false;
    }
}

this is my js party now i'm only checking if field is empty i disable button

2
  • Hi @IR' Shah, how do you want to validate these separate field? Validate if they are a correct format of data? And from your tags which js you use?
    – Rena
    Dec 23, 2022 at 7:24
  • actually, i want to validate the Dob fields, (I have separated fields for day month and year) I want to restrict the user that he can enter day between 1-31 and month in 1-12 and year in 4 digits and between 1950 to 2022 simple Javascript,
    – IR' Shah
    Dec 29, 2022 at 16:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.