I am writing a Java program, and I need to be able to call these two methods, but I'm kind of confused.
These methods need to be able to match the following data:
This would be a sample input if what I am checking...
LASTNAME "Rosemont" #
LASTNAME "Rose Mont" #
USERNAME "jRose!" #
USERNAME "Rose55!" #
So LASTNAME or USERNAME would be the field, the stuff btwn "" is the content, and the # finishes off a valid entry...
checkLastname
A: Must start with an uppercase letter
B: Must only contain letters and spaces
C: Any letter after a space must be capitalized
D: Must be no longer than 20 characters
E: Must be at least one character
checkUsername
A: Must use at least half of the same unique characters as the last LASTNAME read in (you may assume that some LASTNAME appears before any USERNAME)
B: Cannot contain the character & twice consecutively
C: Cannot contain the character | twice consecutively
D: Must be at least five characters long, and no more than 15
E: Cannot contain the , character
F: Must be made up of either letters, numbers, or the following list of characters: !,@,#,$,%,^,&,*,(,),_,-,+,<,>,?,:
This is what I have so far...don't laugh!!!
private static void checkLastname(String line, String field, String content) {
// TODO Auto-generated method stub
{// last name
if(field.equals("LASTNAME")){
if(content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
System.out.println("VALID " + line);
if(!content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
if(!content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
System.out.println("XXXXX " + line
+ ", MALFORMED STRING");
}
}
}
System.out.println("XXXXX " + line
+ ", UNRECOGNIZED FIELD");
}
}
}// end Lastname
private static void checkUsername(String line, String field, String content) {
// TODO Auto-generated method stub
{ // Username
if (field.equals("USERNAME")){
if (content.matches(" ")) {
System.out.println("VALID " + line);
//} else {
if (!content.matches(" ")) {
System.out.println("XXXXX " + line
+ ", MALFORMED STRING");
}
}
//} else {
System.out.println("XXXXX " + line
+ ", UNRECOGNIZED FIELD");
}
}
}// end Username
So, I'm not sure how to get Lastname to be no more than 20 characters and also ensure that the next character after and space is capitalized, and so for Username to have to rely on Lastname is super confusing!!! Tips? Advice? Pleeease!!!