Hi,

I have an international vbs application and I am using regular expressions
to validate the format of the dates entered by the user. It works fine when
running on a English windows PC but it does not recognised valid dates if the
PC has the German version of windows.

This is the code I am using:

Function FormatValRegExp(strValue, strRegExp)

Dim re ' Regular Expression object
Dim response ' response

On error resume next

response = ""
Set re = new regexp ' Create the RegExp object
re.Pattern = strRegExp ' set pattern
re.IgnoreCase = true
response = re.test(strValue)
Set re = nothing

FormatValRegExp = response


End Function

This function wiht the following parameters:
strValue: 31.12.1996
strRegExp: \d{1,2}[.]\d{1,2}[.]\d{2,4}$
returns true in an English version of Windows and false in a German windows.

Any ideas?

Cheers

Juan

Re: Validating dates with regular expressions in a German Windows PC by Roland

Roland
Fri Jul 22 08:01:58 CDT 2005

"Juan Rodriguez" wrote in message
news:25FA9AC2-972E-43B6-B55D-19B3474C5647@microsoft.com...
: I have an international vbs application and I am using regular expressions
: to validate the format of the dates entered by the user. It works fine
when
: running on a English windows PC but it does not recognised valid dates if
the
: PC has the German version of windows.
:
: This is the code I am using:
:
: Function FormatValRegExp(strValue, strRegExp)
:
: Dim re ' Regular Expression object
: Dim response ' response
:
: On error resume next
:
: response = ""
: Set re = new regexp ' Create the RegExp object
: re.Pattern = strRegExp ' set pattern
: re.IgnoreCase = true
: response = re.test(strValue)
: Set re = nothing
:
: FormatValRegExp = response
:
:
: End Function
:
: This function wiht the following parameters:
: strValue: 31.12.1996
: strRegExp: \d{1,2}[.]\d{1,2}[.]\d{2,4}$
: returns true in an English version of Windows and false in a German
windows.

You should consider using yyyy-mm-dd or yyyy/mm/dd or yyyy.mm.dd instead and
this regexp:
(19|20\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])

However, to use it with your dd.mm.yyyy format, you'd change it to:
(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19|20\d\d)

but it will not accept d.m.yyyy. It must be dd.mm.yyyy

You also need another test for leap year.

I have a sample that mixes javacript and vbscript here:
http://kiddanger.com/lab/isdate2.html

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Re: Validating dates with regular expressions in a German Windows by JuanRodriguez

JuanRodriguez
Fri Jul 22 08:21:02 CDT 2005

Roland

Thanks for your interesting reply. I will certainly will take your
suggestions into consideration.

I have actually found out what the problem was with my code in German
windows. Basically, the test function translates the value that returns to
the language of the version of windows and it was returning "Wahr" instead of
"True". This meant that I missed the value completely.

Thanks for you help.

Juan

"Roland Hall" wrote:

> "Juan Rodriguez" wrote in message
> news:25FA9AC2-972E-43B6-B55D-19B3474C5647@microsoft.com...
> : I have an international vbs application and I am using regular expressions
> : to validate the format of the dates entered by the user. It works fine
> when
> : running on a English windows PC but it does not recognised valid dates if
> the
> : PC has the German version of windows.
> :
> : This is the code I am using:
> :
> : Function FormatValRegExp(strValue, strRegExp)
> :
> : Dim re ' Regular Expression object
> : Dim response ' response
> :
> : On error resume next
> :
> : response = ""
> : Set re = new regexp ' Create the RegExp object
> : re.Pattern = strRegExp ' set pattern
> : re.IgnoreCase = true
> : response = re.test(strValue)
> : Set re = nothing
> :
> : FormatValRegExp = response
> :
> :
> : End Function
> :
> : This function wiht the following parameters:
> : strValue: 31.12.1996
> : strRegExp: \d{1,2}[.]\d{1,2}[.]\d{2,4}$
> : returns true in an English version of Windows and false in a German
> windows.
>
> You should consider using yyyy-mm-dd or yyyy/mm/dd or yyyy.mm.dd instead and
> this regexp:
> (19|20\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])
>
> However, to use it with your dd.mm.yyyy format, you'd change it to:
> (0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19|20\d\d)
>
> but it will not accept d.m.yyyy. It must be dd.mm.yyyy
>
> You also need another test for leap year.
>
> I have a sample that mixes javacript and vbscript here:
> http://kiddanger.com/lab/isdate2.html
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>
>

Re: Validating dates with regular expressions in a German Windows by Roland

Roland
Fri Jul 22 13:03:35 CDT 2005

"Juan Rodriguez" wrote in message
news:6FA02881-97CD-4E20-8690-843B854C1E47@microsoft.com...
: Thanks for your interesting reply. I will certainly will take your
: suggestions into consideration.
:
: I have actually found out what the problem was with my code in German
: windows. Basically, the test function translates the value that returns to
: the language of the version of windows and it was returning "Wahr" instead
of
: "True". This meant that I missed the value completely.
:
: Thanks for you help.

Glad you got it figured out Juan.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Re: Validating dates with regular expressions in a German Windows PC by Dr

Dr
Sat Jul 23 12:35:02 CDT 2005

JRS: In article <25FA9AC2-972E-43B6-B55D-19B3474C5647@microsoft.com>,
dated Fri, 22 Jul 2005 04:03:01, seen in news:microsoft.public.scripting
.vbscript, =?Utf-8?B?SnVhbiBSb2RyaWd1ZXo=?= <JuanRodriguez@discussions.m
icrosoft.com> posted :
>
>I have an international vbs application and I am using regular expressions
>to validate the format of the dates entered by the user.

For international work, you should either call for ISO 8601 date field
order YYYY-MM-DD or require the user to specify format; and you should
not assume anything about the system localisation, not even that it
suits the locals.

Use a RegExp /^\d{4}\D\d\d\1\d\d$/ (that works in javascript; I cannot
test it in VBS) to check for four digits, separator, two digits, same
separator, two digits. The RegExp use should return an array including
the YYYY MM DD strings.

Convert those to numbers with CInt.

To validate the actual date, rejecting such as April 31st, try
converting those numbers to CDate with DateSerial, then using the Day
and Month functions to see if you get the same numbers back.

Also, see <URL:http://www.merlyn.demon.co.uk/vb-dates.htm>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.