Click here to Skip to main content
15,944,390 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Need help for below query...

Form has passport expiry field and validation for field is, passport must have at least 6 months validity from current date.

I have to do it in asp.net... so pls help me for this.


What I have tried:

I am using custom validator
I have to do it in asp.net... so pls help me for this.
Posted
Updated 15-Mar-17 2:13am
Comments
Karthik_Mahalingam 15-Mar-17 1:58am    
post the code what you have trid
Graeme_Grant 15-Mar-17 1:59am    
Please don't repost the exact same question under a different user account: Need help for below query...[^]
Member 12840365 15-Mar-17 2:15am    
I have not tried anything yet
Karthik_Mahalingam 15-Mar-17 2:21am    
do it in javascript
what is the format you are using?

Read the password expiry date from the user. Convert it to a DateTime value.
Get the current date using DateTime.Now. Add six months using AddMonths.
Compare the two dates. If the expiry date is the greatest, it's fine. If it isn't, it doesn't last long enough.

This is your homework, so I'll give you no code! But me? I'd do it in JavaScript rather than force a round trip to the server.
 
Share this answer
 
Comments
OriginalGriff 2-Sep-21 9:57am    
Good luck with that ...
$.validator.addMethod("expiryValidator", function (value, element) {
              var val = Date.parse(value);
              if (isNaN(val))
                  return false;

              var d = new Date(val);
              var f = new Date();

              f.setMonth(f.getMonth() + 6);
              if (d < f) {
                  return false;
              }

              return true;
          });

          $(function () {
              var config = {
                  "rules": { "txtPassportExpiryDate": { "required": true, "expiryValidator": true } }
                 , "messages": { "txtPassportExpiryDate": { "required": "Please Enter Passport Expiry Date", "expiryValidator": "The specified date is not valid." } }
              };
              // replace #theForm with your form's id value
              $("#form1").validate(config);

          });
 
Share this answer
 
How To set expiry Date User id and password In VBScript
 
Share this answer
 
Comments
OriginalGriff 24-Sep-22 6:03am    
This is not a solution: it's a poorly asked question.

Please do not post things like this as solutions as it will not generally get you any answers.

Start with Google: we have no idea what your code is like so begin there with your whole question, and refine your search to fit your exact circumstances.
If you can't get it solved that way, at least you will have an idea what information we need in order to help you when you post a question of your own.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900