Reputation: 1271
Is there a way to use user's culture to localize the Range Validator for date? I am looking for a good way to validate date and avoiding to provide a fix format (e.g.: do a dd/mm/yyyy using Regular Expression Validator)
Upvotes: 2
Views: 508
Reputation: 1271
This will be something closest to what I want actually.
Getting user's language preference based on language settings:
userLanguage = Request.UserLanguages[0];
Get ShortDatePattern
base on language:
new CultureInfo(userLanguage).DateTimeFormat.ShortDatePattern;
From here I will use the pattern to validate user's input and to display the required format on the page.
Upvotes: 0
Reputation: 8074
Use the Date.TryParseExact()
method, consulting the documentation.
Use members of the returned My.Application.Culture.CurrentCulture.DateTimeFormat
object, which is of class System.Globalization.DateTimeFormatInfo, to retrieve the date formats for the current culture (there are several formats for every culture, such as long format and short format...).
Upvotes: 1