Date validation Script

416 views
Skip to first unread message

swetha4qtp delhi

unread,
Dec 3, 2008, 4:43:20 AM12/3/08
to mercuryqtp
I have a Screen with Text box which should not accept more than 12 th month , 30 th date and 2008 as year.
 If anyone have code for this please send me.
 
regards
 
swetha
 

Kamran

unread,
Dec 3, 2008, 3:57:23 PM12/3/08
to Mercu...@googlegroups.com
[0-1][0-2]/[0-3][0-9]/200[0-8]
--
Regards,
Kamran

Roman Zilber

unread,
Dec 3, 2008, 4:00:27 PM12/3/08
to Mercu...@googlegroups.com
[0-1][0-9]/[0-3][0-9]/200[0-8]
 :)

Dmitry Motevich

unread,
Dec 3, 2008, 4:46:24 PM12/3/08
to Mercu...@googlegroups.com
What about 12/37/2008?
It matches your pattern :)
--
Dmitry Motevich,
http://motevich.blogspot.com

Roman Zilber

unread,
Dec 3, 2008, 4:56:02 PM12/3/08
to Mercu...@googlegroups.com
Ups, probably the only way:

arr = split(date, ""\")

if arr(0) > 12 OR arr(0) < 0 Then
   report error
End If
if arr(1) > 31 OR arr(1) < 0 Then
...

r rameshwar

unread,
Dec 3, 2008, 9:06:16 PM12/3/08
to Mercu...@googlegroups.com

Hi Swetha

Browser("RFbank").Page("Admincustomerdetails").WebEdit("txtDOB").Set "12/30/2008"

Kamran

unread,
Dec 3, 2008, 9:09:12 PM12/3/08
to Mercu...@googlegroups.com
hope this will work

Dim date_val
 date_val = browser("Thomson ONE Log In").Page("Thomson One [Company Review").Frame("Market Data").WebEdit("WebEdit").GetROProperty("value")
If date_val => 12/30/2008 Then
    msgbox"Date diffrence"
End If
--
Regards,
Kamran

r rameshwar

unread,
Dec 3, 2008, 9:24:11 PM12/3/08
to Mercu...@googlegroups.com
Hi
OptionExplict
Dim dob
Browser("RFbank").Page("CustomerDetails").WebEdit("DateofBer").Set "12/30/08"
dob=Browser("RFbank").Page("CustomerDetails").WebEdit("DateofBer").GetROProperty("Value")
If dob=>12/30/08 Then
       Print "Enter Valid DMY"
End If
 
 
 
 
Rameshwar
 


 

Roman Zilber

unread,
Dec 3, 2008, 11:18:01 PM12/3/08
to Mercu...@googlegroups.com
Ups,

I forgot, there are bunch of Date functions in VBScript
http://www.w3schools.com/VBscript/vbscript_ref_functions.asp
You can convert with CDate string into  Date object.

Roman

On Wed, Dec 3, 2008 at 3:57 PM, Kamran <kkam...@gmail.com> wrote:

venkata koduri

unread,
Dec 4, 2008, 12:41:04 AM12/4/08
to Mercu...@googlegroups.com
Swetha,
 
This is the correct Regular expression for your query.
 
(([0][1-9])|([1][0-2]))[/]([0][1-9])|([1-2][0-9])|([3][0]))[/]([0-9][0-9][0-9][0-8]).
--
Regards..
Venkat

Rick Hall

unread,
Dec 4, 2008, 9:24:56 PM12/4/08
to QTP - HP Quick Test Professional - Automated Software Testing
Close, and much better than the regular expressions that allow
February 30 and other assorted bad dates.

arr = split(date, ""\")
/* month out of range [1..12] */
If arr(0) > 12 OR arr(0) < 1 Then
report error
End If
/* day too small */
If arr(1) < 1 Then
report error
End If
/* there is no year 0, negative numbers are BCE */
If arr(2) = 0 Then
report error
End If
/* 30 days hath September ...*/
If arr(0) = 1 OR arr(0) = 3 OR arr(0) = 5 OR arr(0) = 7 OR arr(0) = 8
OR arr(0) = 10 OR arr(0) = 12 THEN
If arr(1) > 31 Then
report error
End If
End If
If arr(0) = 4 OR arr(0) = 6 OR arr(0) = 9 OR arr(0) = 11 THEN
If arr(1) > 30 Then
report error
End If
End If
If arr(0) = 2 THEN
If arr(1) > 29 Then
report error
End If
If arr(1) = 29 Then
IF /* not Leap Year */ THEN
/* left as an exercise; years, arr(2), divisible by 4 are leap years,
unless they are divisible by 100 when they are not leap years, unless
they are divisible by 400 when they are leap years */
report error
End If
End If
End If

Detailed and messy. But this is the heart of programming. Your
database will choke on bad dates.

Rick

venkata koduri

unread,
Dec 5, 2008, 9:36:23 AM12/5/08
to Mercu...@googlegroups.com
Hi Rick,
 
I appreciate you. In this code year>0 then it pass. If I enter 2008 or 08 both or equal. Right?
My doubt is  if year SHOULD BE 4 CHARACTERS  then how does it work??
 
clarify me.
Thats why I prefer Regular expression.
--
Regards..
Venkat

Roman Zilber

unread,
Dec 5, 2008, 2:51:21 PM12/5/08
to Mercu...@googlegroups.com
oDate1 = CDate("22/05/2008")

oDate2 = CDate("17/06/2008")

msgbox oDate1 - oDate2
msgbox oDate1 < oDate2

rajanikanth b

unread,
Dec 7, 2008, 10:55:05 AM12/7/08
to Mercu...@googlegroups.com
x = 12/30/2008

Dte = Split(x,"/",-1)

mth = Dte(0)
sDay = Dte(1)
Yr =Dte(2)

if Mth>12 then

if Browser().dialog().Static().Exist then ''' for 'Pop Up'''''

Reporter.ReportEvent micpass,"Stpe1" , "pass"

else

Reporter.ReportEvent micfail,"Stpe1" , "Fail"

End if


if sDay>30 then

if Browser().dialog().Static().Exist then ''' for 'Pop Up'''''

Reporter.ReportEvent micpass,"Stpe1" , "pass"

else

Reporter.ReportEvent micfail,"Stpe1" , "Fail"

End if
End if

if Yrr>2008 then

if Browser().dialog().Static().Exist then ''' for 'Pop Up'''''

Reporter.ReportEvent micpass,"Stpe1" , "pass"

else

Reporter.ReportEvent micfail,"Stpe1" , "Fail"

End if


I think it works.





On Wed, Dec 3, 2008 at 3:13 PM, swetha4qtp delhi <sweth...@gmail.com> wrote:



--
Rajanikanth.B
Reply all
Reply to author
Forward
0 new messages