Make and convert the ASP.NET MVC3 and Entity Framework 4 property to uppercase.

I have a database field (zip code) in which I want to contain uppercase characters, spaces and numbers. No lowercase characters or other punctuation marks. I would like to consider this as declarative as possible. One way is to use the DataAnnotation regular expression for validation, [A-Z][0-9]\w(or the like - I'm not a regular expression specialist, but I'm sure that the correct regular expression will be found there). That would do half what I want - it will force the user to type in uppercase, but will not convert to uppercase.

If I want to convert to uppercase, there are some solutions in the question How can I force input to uppercase in an ASP.NET text box? but none of them are particularly declarative. At the moment, I am thinking of a combination of validation and jQuery to detect something with the "uppercaseonly" class and transform the data, but it is a bit dirty.

Did I miss something?

+3
source share
2 answers

CSS text-transform: uppercase ?

http://www.w3schools.com/css/pr_text_text-transform.asp

UPDATE:

Try implementing a custom ModelBinder. Here is an example: http://www.agileatwork.com/custom-model-binder-in-asp-net-mvc/

AddRoles . EF.

+2

, ?

, { get; set; } ;

get { return this.property; }

set { this.property = value.ToUpper(); }
+2

All Articles