CFINPUT Validate date as 1922

I am trying to validate dates. If the person enters a 2 digit year, it accepts it but by default it appears that anything below 30 goes to 2000 and anything 1900 for anything above. How can I validate 26 as 1926 when it assumes I mean 2026? Is there a way to specify a date range? OR how can I force a 4 digit year?

I know I can check after the fact for a future date.

Thanks,
Doug
dBedientAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

js_vaughanCommented:
If you would like to validate it on the server you can do something like this ...

<cfset inputYear = REReplace(FORM.year,'[^0-9]','','ALL')>
<cfif Len(inputYear) EQ 4>
    <!--- Code for a correct input --->
<cfelse>
    <!--- Let them know they made a mistake --->
</cfif>

But the best bet is to use javascript on your front end like i listed below here ...


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Experts Exchange - js_vaughan</title>

<script type="text/javascript">
<!--

      function isFullYear(form) {
      
            var f = form.year.value; // Set year to what your field is called
            
            var re = /^\d{4}$/; // Regular expression to check for 4 digits only
            if (re.test(f)) {
                  return true;
            } else {
                  alert("Please enter a 4-digit year");
                  return false;
            }
      }
      
// -->
</script>

</head>

<body>

<form name="form_name" action="index.htm" onSubmit="return isFullYear(this);">
      <input type="text" name="year" size="5" maxlength="4">
      <input type="submit" value="Submit Year">
</form>

</body>
</html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrichmonCommented:
You cannot change the way it is interpreted.  It is acually a system setting not a CF setting.  So your only choice is to force a full year - or manually ask the user which year they mean.  In either case it is much easier (and in the case of the prompt you have no choice) to not use cfinput
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.