Validation

For questions and postings not covered by the other forums
bhowden
Posts: 2
Joined: Mon Oct 12, 2009 2:49 pm

Validation

Postby bhowden » Mon Oct 12, 2009 2:56 pm

As part of an exercise for an assignment I need to know how to perform validation in Jade. I have a set method which returns a string called LastName and one called FirstName. At the moment this method just returns true I need to know how to change this so that it checks for special characters such as apostrophoses and hyphens and if the string contains any of these return false other wise if all is ok return true.

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Validation

Postby BeeJay » Tue Oct 13, 2009 7:43 am

You would need to code your setDetails method along the lines of the followig:

Code: Select all

setDetails( pFirstName : String ; pLastName : String ) : Boolean ; begin if pFirstName.containsSpecialCharacters or pLastName.containsSpecialCharacters then // Invalid first or last name, so bail now return false ; endif; // The names validate ok, so set the properties and return true to indicate success self.firstName := pFirstName ; self.lastName := pLastName ; return true ; end;
Obviously you then need to create the String::containsSpecialCharacters primitive method to return true/false dependent on whether or not that string contains any of what you consider to be special characters. Given that this is for a programming assignment, I won't write example code for that method. You should, however, review the RootSchema supplied methods on the String primitive as there are existing methods that could help achieve the desired result. In particular, the String::scan**** methods could prove useful in writing an efficient String::containsSpecialCharacters method to suit your requirements.

Cheers,
BeeJay.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 9 guests