File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Validatons using Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Validatons using Strings" Watch "Validatons using Strings" New topic
Author

Validatons using Strings

Phanindra varma
Greenhorn

Joined: Jul 29, 2005
Posts: 14
Hi All,
Can anybody please help me out.

I have a text field i need to validate that text field with the following condtions using strings.

1. It should accept year (eg : 2006)
2. It should accept month (eg : 09/2006)
3. It should accept date (eg : 11/09/2006)
4. It should accept range (eg: 2006-2009)
5. Months (eg: 15 M)
6. years (eg: 5 y)

Can anybody please help me out.

Thanks in Advance.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
What you can do is . Create a userdefined control inherited from TextField and using regular expressions you can validate the text contained in the text field.
[ December 29, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Hmmm, this should be in the Swing/etc... forum, but anyway...

If you are using Swing, check out JFormattedTextField (you should be able to use it directly, without subclassing):
http://java.sun.com/developer/JDCTechTips/2004/tt0504.html
http://java.sun.com/products/jfc/tsc/articles/reftf/index.html
http://java.sun.com/j2se/1.4.2/docs/guide/swing/1.4/ftf.html

Or, you may prefer to use javax.swing.InputVerifier:
http://java.sun.com/developer/JDCTechTips/2005/tt0518.html
http://java.sun.com/developer/JDCTechTips/2001/tt1120.html
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/InputVerifier.html


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Validatons using Strings
 
Similar Threads
Arabic letters in Text object
validations using strings
Group variable validation
Regarding Login
Doubt in field validation using struts