san1 Posted March 19, 2014 Share Posted March 19, 2014 HiI need to use the KeyPress eventto restrict date to MM/DD/YYYY format only. Here's my code:Private Sub txtDoj_KeyPress(ByVal sender As System.Object, ByVal e As System Windows.Forms.KeyPressEventArgs) Handles txtDoj.KeyPressIf Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Thene.Handled = TrueEnd IfI understand that this code allows numbers only. But I do not know how to modify this to allow date format only.Thanks in advance for helping me out. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2014 Share Posted March 19, 2014 That code is checking if each key is a digit, or a control character, or a period. You can change that to allow the characters you want, for example a slash instead of a period. I wouldn't use a keypress handler to check the format of the input though, I would probably use a blur handler so that you can check the format after they move away from the field (so that they are finished). Link to comment Share on other sites More sharing options...
san1 Posted March 19, 2014 Author Share Posted March 19, 2014 Thanks. Could you explain that in code format? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2014 Share Posted March 19, 2014 I'm not going to write your code for you, I'm here to help you learn not do it for you. If you want to show your work and ask questions about it, feel free. Link to comment Share on other sites More sharing options...
san1 Posted March 20, 2014 Author Share Posted March 20, 2014 The code that I shared is all I have to fulfill this because it has to be with KeyPress and the rest of the code in the click event. I just asked for more clarity, perhaps a code example to guide me in the right direction. If you are going to be so blunt for no reason then I dont need your help. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now