Question

replace field value

Asked by: yolish

what I am trying to do is replace a field value and set it to blank if the value isn't a date... I have tried several things without any success.

function validDate(fieldValue,fieldName){
 if (fieldValue.length > 0) {
  var d = fieldValue;
  var fieldName = fieldName;
  d = new Date(d);
  if (isNaN(d))
     alert ('Sorry, not in a valid date format');
     //alert (fieldName)
     fieldName = '';
}
}

where fieldName = document.forms.n_PCOriginalDate.value

thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2001-07-24 at 15:43:59ID20156478
Tags

date

,

field

,

var

Topic

JavaScript

Participating Experts
4
Points
25
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. problem with using isNaN
    Is there a simple way to make sure that a number is a whole number? I am making sure that a user enters their social and the(! isNaN) will accept 123456.89 as a length of nine number. I was trying to use the parseInt but I could not validate the length. parts of my code is...
  2. isNaN - error when trying to validate text field
    I get an "Object Expected" when I try to use my if statement in a function that is called I just want to validate a text field If(isNaN(document.Mainform.NoPicsToRestore.value)) { Alert("You have not entered a Valid number for Pi...
  3. isNaN to accept numbers with commas?
    im using javascript's isNaN().. but i want a number also accepted with commas... ie. -1,000,000.12 any ideas?
  4. isNaN(parseInt(x)) problem
    Okay, This: var a="123"; var b = parseInt(a); alert(isNaN(b)); works. This: var a="123"; alert(isNaN(parseInt(a)); doesn't work. Why?
  5. Javascript isNAN
    Anyone have any clue why this wouldn't work? if (isNaN(form.inquiryPhone.value)==true) { alert("We need a valid phone number in this form (9165551212), please enter it before continuing. "); form.inquiryPhone.focus(); return false; } Frustrated...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: CUTTHEMUSICPosted on 2001-07-24 at 17:17:35ID: 6315462

I found this.
http://www.developer.irt.org/script/1.htm
I'll try to put it into a function that corresponds to your question although the link might be a good start.

 

by: CUTTHEMUSICPosted on 2001-07-24 at 17:30:25ID: 6315490

On other thing can you use client side vbScript (IE Only)?

 

by: CUTTHEMUSICPosted on 2001-07-24 at 17:34:50ID: 6315499

Here is a script that I found.

/*
   Script:                 dateValidate.js

   Source:                 http://www.shastrynetcom/

   Author:                 Subramanya Shastry Y V H
                                       shastry@email.com

   Description:            Generic Date validation routine.

   Usage:                  Include this file with script tag and pass the date value to be
                           validated to the function 'isProperDate()'

                                       This file can be included with the script tag
                                       <script src="dateValidate.js"></script>

                                       It is my advice that you include this file directly from my
                                       site, so that you get to use the script which is up-to-date.
                                       You can do so with the script tag
                                       <script src="http://www.shastrynet.com/javascript/dateValidate.js"></script>

   Copyright:              This script can be freely used with or without modifications.
 
                           The author cannot be held responsible for any possible mistakes
                           in the coding. It is the responsibility of the user to make
                           sure that the code is working fine and is bug-less.
 
                           This Script cannot be distributed without prior permission from
                           the author.
*/

//------------------------------------------------------------------------------------
// function: isProperDate
//           Function to tell whether the given date is valid or not
//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//           or mm-dd-yyyy or mm-dd-yy
//------------------------------------------------------------------------------------
function isProperDate(argDate) {
      var tmpDay = getDay(argDate)
      var tmpMon = getMonth(argDate)
      var tmpYear = getYear(argDate)

      return isProperDay(tmpDay, tmpMon, tmpYear) && isProperMonth(tmpMon) && isProperYear(tmpYear)
}

//------------------------------------------------------------------------------------
// function: isWhiteSpace
//           Function to check whether the given argument consists of charactes other
//           than a space and \t
//------------------------------------------------------------------------------------
function isWhiteSpace(argWhiteSpace) {
      argWs = argWhiteSpace.toString()
      
      for (var intI=0; intI < argWs.length; intI++)
            if (argWs.charAt(intI) != ' ' && argWs.charAt(intI) != '\t')
                  return false
      
      return true
}

//------------------------------------------------------------------------------------
// function: isLeapYear
//           Function to tell, whether the given year is leap year or not
//------------------------------------------------------------------------------------
function isLeapYear(argYear) {
      return ((argYear % 4 == 0) && (argYear % 100 != 0)) || (argYear % 400 == 0)
}

//------------------------------------------------------------------------------------
// function: daysInMonth
//           Function to return the maximum number of days in a given month of a
//           given year
//------------------------------------------------------------------------------------
function daysInMonth(argMonth, argYear) {
      switch (Number(argMonth)) {
            case 1:            // Jan
            case 3:            // Mar
            case 5:            // May
            case 7:            // Jul
            case 8:            // Aug
            case 10:            // Oct
            case 12:            // Dec
                  return 31;
                  break;
            
            case 4:            // Apr
            case 6:            // Jun
            case 9:            // Sep
            case 11:            // Nov
                  return 30;
                  break;
            
            case 2:            // Feb
                  if (isLeapYear(argYear))
                        return 29
                  else
                        return 28
                  break;
            
            default:
                  return 0;
      }
}

//------------------------------------------------------------------------------------
// function: getDateSeparator
//           Function to return the date separator
//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//           or mm-dd-yyyy or mm-dd-yy
//------------------------------------------------------------------------------------
function getDateSeparator(argDate) {
      // Are there invalid separators?
      if ((argDate.indexOf('-') > 0) && (argDate.indexOf('/') > 0))
            return ' '

      if (argDate.indexOf('-') > 0)
            return '-'
      else
            if (argDate.indexOf('/') > 0)
                  return '/'
            else
                  return ' '
}

//------------------------------------------------------------------------------------
// function: getYear
//           Function to return the year part of the given date.
//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//           or mm-dd-yyyy or mm-dd-yy
//------------------------------------------------------------------------------------
function getYear(argDate) {
      var dateSep = getDateSeparator(argDate)
      
      if (dateSep == ' ')
            return 0

      if(argDate.split(dateSep).length == 3)
            return argDate.split(dateSep)[2]
      else
            return 0
}

//------------------------------------------------------------------------------------
// function: getMonth
//           Function to return the month part of the given date.
//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//           or mm-dd-yyyy or mm-dd-yy
//------------------------------------------------------------------------------------
function getMonth(argDate) {
      var dateSep = getDateSeparator(argDate)
      
      if (dateSep == ' ')
            return 0

      if(argDate.split(dateSep).length == 3)
            return argDate.split(dateSep)[0]
      else
            return 0
}

//------------------------------------------------------------------------------------
// function: getDay
//           Function to return the day part of the given date.
//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
//           or mm-dd-yyyy or mm-dd-yy
//------------------------------------------------------------------------------------
function getDay(argDate) {
      var dateSep = getDateSeparator(argDate)
      
      if (dateSep == ' ')
            return 0

      if(argDate.split(dateSep).length == 3)
            return argDate.split(dateSep)[1]
      else
            return 0
}

//------------------------------------------------------------------------------------
// function: isProperDay
//           Function to tell whether the given day of the given month is valid
//------------------------------------------------------------------------------------
function isProperDay(argDay, argMonth, argYear) {
      if ((isWhiteSpace(argDay)) || (argDay == 0))
            return false

      if ((argDay > 0) && (argDay < daysInMonth(argMonth, argYear) + 1))
            return true
      else
            return false
}

//------------------------------------------------------------------------------------
// function: isProperMonth
//           Function to tell whether the given month is a valid one
//------------------------------------------------------------------------------------
function isProperMonth(argMonth) {
      if ((isWhiteSpace(argMonth)) || (argMonth == 0))
            return false
      
      if ((argMonth > 0) && (argMonth < 13))
            return true
      else
            return false
}

//------------------------------------------------------------------------------------
// function: isProperYear
//           Function to tell whether the given Year is a valid one
//------------------------------------------------------------------------------------
function isProperYear(argYear) {
      if ((isWhiteSpace(argYear)) || (argYear.toString().length > 4) || (argYear.toString().length == 3))
            return false
      
      switch (argYear.toString().length) {
            case 1:
                  if (argYear >=0 && argYear < 10)
                        return true
                  else
                        return false
                  
            case 2:
                  if (argYear >=0 && argYear < 100)
                        return true
                  else
                        return false
                  
            case 4:
                  if (((argYear >=1900) || (argYear >=2000)) && ((argYear < 3000) || (argYear < 2000)))
                        return true
                  else
                        return false
            
            default:
                  return false
      }
}

 

by: CJ_SPosted on 2001-07-25 at 00:30:41ID: 6316271

function isValidDate(dateStr)
{
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
  // To require a 4 digit year entry, use this line instead:
  // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?
  if (matchArray == null)
  {
    // alert("Date is not in a valid format.")
    return false;
  }
  month = matchArray[3]; // parse date into variables
  day = matchArray[1];
  year = matchArray[4];
  if (month < 1 || month > 12)
  { // check month range
    // alert("Month must be between 1 and 12.");
    return false;
  }
  if (day < 1 || day > 31)
  {
    // alert("Day must be between 1 and 31.");
    return false;
  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31)
  {
    // alert("Month "+month+" doesn't have 31 days!")
    return false
  }
  if (month == 2)
  { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day==29 && !isleap))
    {
      // alert("February " + year + " doesn't have " + day + " days!");
      return false;
    }
  }
  return true; // date is valid
}



function validDate(field)
{
   if(!isValidDate(field.value))
   {
       alert ('Sorry, not in a valid date format');
       field.value="";
   }
}

Now call it like:
<input type=text onChange="validDate(this)">

regards,
CJ




if (!isValidDate('30/02/2000')) alert('Invalid date!');

 

by: lexxwernPosted on 2002-07-14 at 01:26:00ID: 7152077

________________________________________
do not accept this comment as the answer

this question has been abandoned. experts please
post recommendations below to help the moderators.


________________________________________
recommendation
split.
CJ
CUTTHEMUSIC

 

by: NetminderPosted on 2002-07-26 at 20:24:32ID: 7181505

Per recommendation, force-accepted.

Netminder
CS Moderator

CJ_S: points for you at http://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20328609

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...