How do I get the length of a string field?

You are looking for DescribeFieldResult.getLength():

For string fields, returns the maximum size of the field in Unicode characters (not bytes).

Schema.DescribeFieldResult F = Account.AccountNumber.getDescribe();
Integer lengthOfField = F.getLength();

This is pretty straightforward in both Apex and Visualforce using describes:

Apex:

Integer len = SObjectType.Object__c.Fields.Field__c.Length;

Visualforce:

{!$ObjectType.Object__c.Fields.Field__c.Length}

integer fieldLength = Schema.SObjectType.CustObj__c.fields.CustField__c.getLength();

for more info