• Post Reply Bookmark Topic Watch Topic
  • New Topic

More than one period  RSS feed

 
Neil Forrest
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm stumped. My isValid()method ensures that a fileName is in the proper format when inputted into a textfield. Below are the criteria for an acceptable input. How do I code that fileName can only contain exactly one period, "."?

private boolean isValid(String fileName) {
if (!fileName.endsWith(".bst")) {
newsF.setText("Filename is not valid--must end with .bst");
return false;
} else if (!Character.isLetter(fileName.charAt(0))) {
//blah blah
} else if...WHAT HERE...
newsF.setText("The text in the BST FILE field is not a valid--must not contain more than one period");
return false;
}else
return true;
}

It's probably simple but I can't figure it out...
Thanks,
Neil
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if(fileName.split("\\.",-1).length > 2)
 
Neil Forrest
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome, thanks soooo much.
Neil
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!