Is there a way to get the max size of a varchar textfield?
There's no single function that will extract the value for you, but field_info_field() will get you an array that contains the data:

$info = field_info_field('field_foo');
if (isset($info['columns']['value']['length'])) {
  // Do something with $info['columns']['value']['length']
}


It it's a core text field, value will always be the name of the column you need to check. For other field types it may differ.