Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation in core java

 
pravin rasal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to validate text, number and email id in core java . When user enter invalid text or number or email-id it immediately show the error message in tool tip or in label using pattern matching
Please help me
Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll assume that this is in regards to a web UI as you posted it in the Servlets forum.

In that case, Java will not be of any help. If you want immediate feedback and display feedback in the browser, you'll need to employ JavaScript.
 
Daniel Doboseru
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, from what I know, you can use listeners on servlets, and is not very complicated.
You can declare it very easy. Eg:

and afterwards deploy it as:

So basically what you have to do is using a some kind of lostfocus/onblur event to trigger the validation. But I'm not sure this would work, in which case, what Bear said seems the best option: use JavaScript, and after the data was validated pass it forward.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server-side listeners cannot be used to monitor client-side events.
 
Daniel Doboseru
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh...I thought they can be triggered by the corresponding action on the listened object, no matter the source. My bad then. Thanks for the clarification Bear.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I'll assume that this is in regards to a web UI as you posted it in the Servlets forum.

In that case, Java will not be of any help. If you want immediate feedback and display feedback in the browser, you'll need to employ JavaScript.


Or you could use a combination of Ajax & Server side processing using Java... here's a link to read up more ...
Of course if you have simple validation like isNumberic, isString, maxLength - you've better off using javascript backed by a second level server side validation!! (Never trust what the client send you, ooh well almost never )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic