Not quite.
I revised validateDate() a bit. How about something like this?
Main Topics
Browse All TopicsGreetings all,
A former employee put this js file together but I could not find out it is being called.
Can you please help?
Here is a snippet of the code and how I am trying to call it.
function validateField( fld, flags, name )
{
// alert("validate(" + fld.value + "," + flags + "," + name + ")");
var ftype = flags.charAt(0).toUpperCas
var numat = 1;
var zeroOk = false;
var minSize = 0;
var maxSize = 255;
if ( flags.charAt(1).toUpperCas
{
zeroOK = true;
numat = 2;
}
if ( flags.length > numat )
{
var nums = flags.substring(numat).spl
minSize = parseInt(nums[0]);
if ( nums.length > 1 ) maxSize = parseInt(nums[1]);
}
// okay, ready for anthing...he says
var fval = null;
switch ( ftype )
{
case "C":
fval = validateCurrency(fld);
if ( fval == null ) return name + " is not a valid currency value";
if ( fval == 0 && ! zeroOk ) return name + " can not be zero";
if ( fval < minSize || fval > maxSize)
return name + " must be between " + minSize + " and " + maxSize;
return "";
case "D":
fval = validateDate(fld);
if ( fval == null ) return name + " is not a valid date of the form mm/dd/yyyy";
return "";
case "E":
fval = validateEmail(fld);
if ( fval == null ) return name + " is not a valid email address";
return "";
case "F":
fval = validateFloat(fld);
if ( fval == null ) return name + " is not a valid decimal value";
if ( fval == 0 && ! zeroOk ) return name + " can not be zero";
if ( fval < minSize || fval > maxSize)
return name + " must be between " + minSize + " and " + maxSize;
return "";
case "I": case "N":
fval = validateInteger(fld);
if ( fval == null ) return name + " is not a valid numeric value";
if ( fval == 0 && ! zeroOk ) return name + " can not be zero";
if ( fval < minSize || fval > maxSize)
return name + " must be between " + minSize + " and " + maxSize;
if ( ftype == "I" && fval < 0 ) return name + " cannot be negative";
return "";
case "P":
fval = validatePhone(fld);
if ( fval == null ) return name + " is not a valid 10 or 11 digit phone number";
return "";
case "S":
fval = fld.value.replace(/^\s+/,"
fld.value = fval;
if ( fval < minSize || fval > maxSize)
return name + " must have between " + minSize + " and " + maxSize + " characters";
return "";
case "T":
fval = validateTime(fld);
if ( fval == null ) return name + " is not a valid time of the form hh:mm:ss";
return "";
case "R":
var rre = new RegExp(flags.substring(1))
if ( ! rre.test(val) ) return name + " does not match required pattern";
return "";
case "X": case "*":
var cbs = fld.form.elements[ fld.name ];
if ( cbs.length == null )
{
// single checkbox...so it can only be optional or not
if ( ! cbs.checked && minSize > 0 ) return "You must check in checkbox " + name;
return "";
}
if ( cbs[0] != fld ) return "#"; // special flag: not first checkbox of set
var cnt = 0;
for ( c = 0; c < cbs.length; ++c )
{
if ( cbs[c].checked ) ++cnt;
}
if ( cnt < minSize || cnt > maxSize )
{
return "You must check " + minSize + " to " + maxSize + " " + name + " checkboxes";
}
return "";
default:
return "\n*** ERROR: Invalid type flag, " + ftype + "\n";
}
}
function validateDate(fld)
{
var dateRE = /^(0?[1-9|1[012])\-(0?[1-9
// var dateRE = /^\d\d?\-\d\d?\-(19|20)\d\
var val = fld.value.replace(/[\s\/\.
val = val.replace(/[^\d\-]/g,"")
val = val.replace(/\-+/g,"-");
if ( ! dateRE.test(val) ) return null;
var pcs = val.split(/\-/);
if ( pcs.length != 3 ) return null;
var mn = parseInt(pcs[0])-1;
var dt = new Date( parseInt(pcs[2]), mn, parseInt(pcs[1]) );
if ( mn != dt.getMonth() ) return null;
fld.value = val;
return val;
}
THen I would like to use the above to ensure date field is not blank.
<input type=text name=sentDate value="">
How do I use the js with the above input box?
Thanks a million
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
hi HonorGod,
I am getting the same behavior I was getting when I was using the onblur="validateDate(this)
THis is what I use and when I click submit, it submits the record without raising any alert that that field cannot be blank.
Same I get when I use your code.
I would like to see a message that says, "date field cannot be blank"
Thanks for your prompt response.
As stated, I am sure I was doing something wrong.
However, I figured out a better way to use the original code with CASE statements.
on the input textbox, I was able to use this:
<input name="sentDate" id=":D:" value=""> and on the form tag, I used onsubmit event handler <form name =formname onSubmit return="validateForm;"> and it seems to be working now.
It took me all night to figure this out given that I had to use it this morning prior to afternoon demo.
Many, many thanks for all your assistance and patience HonorGod.
Business Accounts
Answer for Membership
by: HonorGodPosted on 2009-07-05 at 18:23:57ID: 24781942
You could use the second function, like this:
Select allOpen in new window