Wednesday, April 7, 2010

Decimal Regular Expression

The following regular expression checks for a number that can contain up to two decimal places.

^\d*(\.\d{1,2})?$

matches:

123
123.1
123.12

not matches:

123.
123.123

Monday, March 29, 2010

NSMailDelivery undeclared

I've been playing around with Objective C using the Cocoa framework ever since I got my Mac for Christmas.

I was following a dummies guide to sending emails using Cocoa and I came across the following show stopper compilation error :

"error: 'NSMailDelivery' undeclared (first use in this function)"

Not much joy online looking for a solution, seems everyone else who was inflicted with this error was advised to use some other mail class due to NSMailDelivery being dropped by Apple with no successor in Cocoa which seemed odd.

Anyway here's how I solved the problem. By default on my Mac Cocoa projects are targeted for a 64 bit architecture environment, when I changed the architecture to 32-bit universal the project compiled.

I changed the target architecture by clicking on the project name under "Groups & Files" to highlight it.
Then I clicked on the "Info" icon to open the project info dialog, next I clicked on the "Build" tab and changed the architecture value to "32-bit Universal".

I'm guessing switching to a 32 bit architecture will fix simular error messages with different classes I saw people enquiring about while I was looking into this problem.

Monday, December 21, 2009

Thursday, December 17, 2009

Accessing the values of a SPFieldChoice

I've got a sharepoint content page that needs to populate a drop down list with the choice values stored in a site column field of type choice.

The field is defined as follow:

Name="AgeOptions"
DisplayName="Age Options"
RichText="TRUE"
RichTextMode="FullHtml"
Required="FALSE"
Group="SIA Enquiry Form"
ID="{119EFAFF-63D3-4d61-A393-06DE18A91093}"
SourceID="http://schemas.microsoft.com/sharepoint/v3">

Select an option below
10-15
15-20
20-25
25-30
30-35
Over 35




I used the following code to access the field from the code behind of my page layout:
 
SPField field = SPContext.Current.Fields["Age Options"];

if (field != null)
{
Response.Write("Found the Age options field: " + field.InternalName + " Type: " + field.TypeAsString);

SPFieldChoice ageOptions = (SPFieldChoice) field;

StringCollection choices = ageOptions.Choices;

for (int i = 0; i < choices.Count; i++)
Response.Write("Choice ->> " + choices[i] + "
");

}
else
Response.Write("Age options not found.");

Monday, September 28, 2009

Regular Expression String Length Restriction

^.{0,100}$

Accepts a string of 0 to 100 characters