• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pattern  RSS feed

 
Robert Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI I AM DEVELOPING A TAX RETURN PROGRAM AND I GOT STUCK IN THE VALIDATION OF ONE FIELD WHICH IS FOR THE SURNAME I FIND IT HARD TO GET THE CORRECT SYNTAX I TRIED THIS

tfFullName.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent evt)
{
String text= tfFullName.getText();

Pattern pattern = Pattern.compile("['a-zA-Z][a-zA-Z ']*");

Matcher matcher = pattern.matcher(text);

THIS CODE INSIDE THE PARENTHESIS IS VALID BUT GIVE ME AN UNLIMITED NUMBER OF STRING AND I ONLY NEED FOR ONE OR TWO FOR EXAMPLE I WISH TO VALIDATE
FERGUSON FOR ONE SURNAME AND
VAN VOWEL OR GARCIA MARQUEZ FOR TWO SURNAMES
IT WOULD BE EVEN BETTER IN SOME ONE CAN HELP ME TO GET SPECIAL SURNAMES LIKE
O'Connor
MacDonald
Smith-Henderson
ANYONE WHO SEE THIS MESSAGE THANKS FOR THE TIME AND I WILL APPRECIATED YOUR HELP
 
dennis deems
Ranch Hand
Posts: 808
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quiet down, no need to shout.

Here is a great site that lets you test a regular expression; I use it whenever I have a problem like this. However: you need to find a way to articulate the rules for your text validation -- completely, precisely, and unambiguously. Otherwise you will just be guessing.
 
Robert Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Deems wrote:Quiet down, no need to shout.

Here is a great site that lets you test a regular expression; I use it whenever I have a problem like this. However: you need to find a way to articulate the rules for your text validation -- completely, precisely, and unambiguously. Otherwise you will just be guessing.


thank you it works now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!