I have a travel booking application. I wish to check all future bookings to see whether any journeys on the same day also are either starting or ending in the same place.
I can use the post code field to establish where journeys are starting from and ending - UK post codes are split into two parts and I wish to use the first part only which specifies the general area.
I want to identify all bookings where the journey times are within an hour of each other and where either the origin or the destination matches the first part of the post code.
I have a implemented the following to ensure that the post code is correctly input and formatted:
- // Ignore the space and convert the postal code into capitals
- ignoreCase = (input.Address_post_code.getAlphaNumeric()).toUpperCase();
- // Check with regEx
- temp = (ignoreCase).replaceFirst("(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKPS-UW])[0-9][ABD-HJLNP-UW-Z]{2})","");
- if (temp == "")
- {
- // Get the length of the formatted correct Postal Code
- len = (ignoreCase).length();
- // Get the second set of the string (ANN format)
- secondSet = (ignoreCase).subString((len - 3),len);
- // Get the remaining First set of the string
- firstSet = (ignoreCase).subString(0,(len - 3));
- // Alter the postal code to be in Capitals with an empty space between the first set and the second set
- input.Address_post_code = firstSet + " " + secondSet;
- }
- else
- {
- alert "Invalid Postal Code"; cancel submit;
- }
But I'm now not sure where to now start to develop a function to achieve this.
Thanks in advance for your help.
Andrew