- <script language = "Javascript">
-
/**
-
* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
-
*/
-
// Declaring valid date character, minimum year and maximum year
-
var dtCh= "/";
-
var minYear=1900;
-
var maxYear=2100;
-
-
function isInteger(s){
-
var i;
-
for (i = 0; i < s.length; i++){
-
// Check that current character is number.
-
var c = s.charAt(i);
-
if (((c < "0") || (c > "9"))) return false;
-
}
-
// All characters are numbers.
-
return true;
-
}
-
-
function stripCharsInBag(s, bag){
-
var i;
-
var returnString = "";
-
// Search through string's characters one by one.
-
// If character is not in bag, append to returnString.
-
for (i = 0; i < s.length; i++){
-
var c = s.charAt(i);
-
if (bag.indexOf(c) == -1) returnString += c;
-
}
-
return returnString;
-
}
-
-
function daysInFebruary (year){
-
// February has 29 days in any year evenly divisible by four,
-
// EXCEPT for centurial years which are not also divisible by 400.
-
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
-
}
-
function DaysArray(n) {
-
for (var i = 1; i <= n; i++) {
-
this[i] = 31
-
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
-
if (i==2) {this[i] = 29}
-
}
-
return this
-
}
-
-
function isDate(dtStr){
-
var daysInMonth = DaysArray(12)
-
var pos1=dtStr.indexOf(dtCh)
-
var pos2=dtStr.indexOf(dtCh,pos1+1)
-
var strMonth=dtStr.substring(0,pos1)
-
var strDay=dtStr.substring(pos1+1,pos2)
-
var strYear=dtStr.substring(pos2+1)
-
strYr=strYear
-
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
-
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
-
for (var i = 1; i <= 3; i++) {
-
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
-
}
-
month=parseInt(strMonth)
-
day=parseInt(strDay)
-
year=parseInt(strYr)
-
if (pos1==-1 || pos2==-1){
-
alert("The date format should be : mm/dd/yyyy")
-
return false
-
}
-
if (strMonth.length<1 || month<1 || month>12){
-
alert("Please enter a valid month")
-
return false
-
}
-
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
-
alert("Please enter a valid day")
-
return false
-
}
-
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
-
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
-
return false
-
}
-
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
-
alert("Please enter a valid date")
-
return false
-
}
-
return true
-
}
-
-
function ValidateForm(){
-
var dt=document.frmSample.txtDate
-
if (isDate(dt.value)==false){
-
dt.focus()
-
return false
-
}
-
return true
-
}
-
-
</script>
-
this is the javascript i am using ..it works properly but if there is a apace at beginning or at last of date it gives "Please enter a valid 4 digit year" which is correct but my client wants the space to be ignored and no msg to be dispalyed ..how to do it..
Thanks,
Pradeep
8 1612
use the ltrim function (Use google for specifics)
Change - function ValidateForm(){
-
-
//this
-
var dt=document.frmSample.txtDate
-
-
-
-
if (isDate(dt.value)==false){
-
dt.focus()
-
return false
-
}
-
return true
-
}
to something like - var dt=ltrim(document.frmSample.txtDate);
-
.....
use the ltrim function (Use google for specifics)
Change
function ValidateForm(){
//this
var dt=document.frmSample.txtDate
if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}
to something like
var dt=ltrim(document.frmSample.txtDate);
.....
if i use it it escapes the space but the javascript doesnot work only..how to correct it;
sorry what i gave you is not java syntax, it is vb/sql syntax
try dt.value.replace(" ","")
this replaces all the spaces with an empty string
sorry what i gave you is not java syntax, it is vb/sql syntax
try dt.value.replace(" ","")
this replaces all the spaces with an empty string
- function ValidateForm(){
-
var dt=document.frmSample.txtDate
-
if (isDate( dt.value.replace(" ","") )==false){
-
dt.focus()
-
return false
-
}
-
return true
-
}
hey look i have put ur code in the function near the isDate calling function but not working.....any other idea....
Thanks,
Pradeep
- function ValidateForm(){
-
var dt=document.frmSample.txtDate
-
if (isDate( dt.value.replace(" ","") )==false){
-
dt.focus()
-
return false
-
}
-
return true
-
}
hey look i have put ur code in the function near the isDate calling function but not working.....any other idea....
Thanks,
Pradeep
Really srry its working but only for a single space not for multiple spaces ..how to do tht..
did you notice that there are no closing semicolons in your isDate function?
is the code making it into the isDate function and then failing or is it failing at the isDate function call?
gits 5,390
Expert Mod 4TB
hi ...
you could use the following function: - function trim_value(val) {
-
var re = /\s/g;
-
-
return val.replace(re, '');
-
}
-
then in your validate-function call: - var dt = trim_value(document.frmSample.txtDate);
kind regards
hii Thanks for every ones help..
i finally used this
function trim_value(val) {
var re = /\s/g;
return val.replace(re, '');
}
function validatestring(){
var dt=document.vehicleform.Date
if (isDate(trim_value(dt.value))==false){
dt.focus()
return false
}
return true
}
and it is working fine..Thanks Delerna and gits
Thanks,
pradeep
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dr John Stockton |
last post by:
It has appeared that ancient sources give a method for Numeric Date
Validation that involves numerous tests to determine month length;
versions are often posted by incomers here. That sort of code...
|
by: Brian Conway |
last post by:
I am having some validation and insertion problems. I am using a date
picker that takes the selected date and puts it to ("dd-MMM-yyyy") format,
as this was the only format that Oracle would...
|
by: Paul |
last post by:
Hi,
I have a form where a user is required to enter a start date and an
end date. Both are required and must between a specific date range
(e.g. 01/01/1900 and 01/01/2099) and the end date...
|
by: James P. |
last post by:
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the...
|
by: Diego |
last post by:
Can I validate (possibly with a compare validator) a Date entered by the
user based upon his regional settings?
I.e. if a user is american the format would be mm/dd/yyyy, if brittish
dd/mm/yyyy...
|
by: Brendan Reynolds |
last post by:
In an ASP.NET 1.1 app I have the following range validation control. This is
an intranet app that will be used only within Ireland, so all date input is
expected to be in dd/mm/yyyy format.
...
|
by: Petyr David |
last post by:
Just looking for the simplest. right now my perl script returns an
error messge to the user if the date string is invalid. would like to
do this before accessing the server.
TX
|
by: =?Utf-8?B?Q2hyaXM=?= |
last post by:
I have VS 2005 (C#)
There is a control numericUpDown so you can spin numeric values. What I need
to do is to spin date (+- one day). How to do that? Moreover, I want a user
to type the date as...
|
by: John Smith |
last post by:
Hello, I have a VB.NET application with a Windows form that have
several textboxes fields where I have dates entered. I would like to
do a date validation check after the the field is updated, so...
|
by: Stang02GT |
last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do exactly what i need it to do, but i am not sure how to...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |