winforms - how to accept value in date format in textbox in C# windows form? -


i have field in windows form asks user enter birth date... how validate form accept numbers , "/"( separator symbol ) , in dd/mm/yyyy format.. day should less 31, month should less 12 , year not greater 2012

textbox not control accept datetime input. there built in control datetimepicker should used instead. problem approach if masking of textbox 1 format dd/mm/yyyy user may want enter in mm/dd/yyyy. so, quite lot of error handling. whereas need not worry such thing in case of datetimepicker.

even if want go textbox. this,

datetime dt; if (datetime.tryparseexact(yourtexbox.text.trim(), "yourformattoaccept", cultureinfo.invariantculture, datetimestyles.none, out dt)) {    //your code if parsing successful } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -