Skip to Content
author's profile photo Former Member
Former Member

DOB : Date validation with 4 conditions

Hi Friends,

I need help here.

In a webdynpro form when the user click on save , this DOB field should be validate these with 4 conditions,

1. Should not enter null

2. The date not be the future date

3. The date user entered should be less than 18 years compare to current system date

4. The date user entered not less than 1908.

I tried few options but I am not able to make it work correctly with all above validations .please help me!!

regards

Peter

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 30, 2008 at 04:18 AM

    Hi Peter,

    Try doing in following approach

    1. Get the entered date value YYYY-mm-dd and replace into YYYYmmdd format.

    Get the current system date and compare with entered date

    ValidFrom = wdContext.currentContextElement().getValidFrom();

    if(ValidFrom!=null)

    from = ValidFrom.toString().replaceAll("-","");

    else

    // Show message Date value is null

    2. if(enteredDate > currentDate)//YYYYmmdd > YYYYmmdd

    // Show message entered Date should not greater than today date

    3. current year YYYY - 0018 = NewYYYYmmdd // subract the eighteen years

    if(enteredDate > NewYYYmmdd)

    // manager.reportWarning("Entered date should be 18 years less than current date");

    4. if(YYYYmmdd < 19080101) // entered date < 19080101

    // manager.reportWarning("Entered date should not be less than 19080101");

    Getting current date:

    Date Validation

    you can also search here for date validations(formatting etc).

    Regards, Suresh KB

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Guys, Thank you very much.

      As I am beginner and the eay you explained help me to start the task. Finally made it to work.

      Calendar dateOfBirth = Calendar.getInstance();

      Calendar today = Calendar.getInstance();

      if(wdContext.currentContextElement().getDOB() != null){

      dateOfBirth.setTime(wdContext.currentContextElement().getDOB());

      }

      int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);

      wdComponentAPI.getMessageManager().reportSuccess("Age : "+age);

      if (wdContext.wdContext.currentContextElement().getDOB()==null || wdContext.wdContext.currentContextElement().getDOB().after(new Date(System.currentTimeMillis()))|| age <= 15 || age >100 )

      {

      wdComponentAPI.getMessageManager().reportException("Please enter the valid date of birth", false);

      }

      else

      {

      wdComponentAPI.getMessageManager().reportSuccess("You enter valid date");

      }

      Any comments welcome.

      Thanks Guys .

      Rewarded points.

      Edited by: peter Mark on Jan 31, 2008 12:40 AM

  • author's profile photo Former Member
    Former Member
    Posted on Jan 30, 2008 at 06:42 AM

    Hi Peter,

    Check this document, it hadles date validation.

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/837d9290-0201-0010-1381-e633fe17cb14

    regards

    Sumit

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.