VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. tra

by xz-Bit (3 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. trace spaces '3. read input characters

Rate a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. tra



'place a command button and a text box
'paste this code either on text box event procedure(e.g. text1_lostfocus())
Private Sub Command1_Click()
dim i

if trim(text1) <> "" then
  if (mid(text1,3,1)=":" and mid(text1,6,1)=":") and mid(text1,9,1)=" " and (mid(ucase(text1),10,2) = "AM" or mid(text1,10, 2) ="PM" then
     'meet valid tie format
     
     'validate hh not > 12
      if mid(text1,1,2) > 12 then
  msgbox"Number of hours exceed",,"Error"
      end if
      
      'validate mm not  59
      if mid(text1,4,2) > 59 then
         msgbox"Number of minutes exceed",,"Error"  
      end if
      
      'validate ss not > 59
      if mid(text1,7,2) > 59 then
msgbox"Number of seconds exceeds",,"Error"
      end if

      'validate if input string are valid in format
      '8 represents the maximum value of text box
      for i = 1 to 8
if instr("0123456789:", mid(text1,i,1) = false then
   msgbox"Undentified string.",,"Error"
   exit for
        end if
       next i
'empty value
else
   msgbox"Invalid time format",,"Error"
end if

  


Download this snippet    Add to My Saved Code

a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. tra Comments

No comments have been posted about a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. tra. Why not be the first to post a comment about a comprehensive way to validate if a user imput a valid time format. '1. identify structure '2. tra.

Post your comment

Subject:
Message:
0/1000 characters