cancel
Showing results for 
Search instead for 
Did you mean: 

DOB : Date validation with 4 conditions

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

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:

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

Regards, Suresh KB

Former Member
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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-e633fe17...

regards

Sumit