Monthly Archives: June 2014

Data Annotations MVC Validation

If you are looking for the attribute or data annotation to be used in your MVC model e.g. to validate email addresses you may in reality be looking for the DataType Enumeration (remember it next time you google it).

Actually, the EmailAddress data type doesn't work for the validation. I use my own regex:

[RegularExpression(@"^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", ErrorMessage = "Not a valid e-mail")]

This is just a little note for me, as I lost quite some time to find this.

UPDATE: the regular expression above is wrong, email like [email protected] was treated as invalid (to be updated when I have free time).

This works (with .net 4.5):

[Required]
[DataType(DataType.EmailAddress)]
[EmailAddress]
public string Email { get; set; }

Paste in plain text on Mac OS X

If you like to copy and then paste in plain text you may know (for Windows) PureText.

For Mac, I found Flycut, which is much more powerful, but if you don't care about the advanced features you can still use it the simple way.

To paste as plain text, simply copy something, then use the shortcut Command + Shift + V.

If you hold Command + Shift + V, you can navigate with the "left" and "right" arrows your clipboard history. If you don't want that, or you want to customize it (say you want it to remember only the last 5 , check the Flycut preferences. Flycut has an icon in the top bar. Click it and then click on "Preferences".

Remember to add it to your Startup items, else you have to open it manually all the time.

Fix key repeat on Mavericks

It seems that Mac OS X has (still) this annoying bug. If in Preferences > Keyboard > you set "Key Repeat" to "fast" and "Delay Until Repeat" also to fast, the system won't obey it.

To fix this, open the terminal, run this command (just copy/paste this, no sudo needed):

defaults write -g ApplePressAndHoldEnabled -bool false

Then Log Out. Log in ad enjoy the key repeat working as it should.