The moose likes HTML, CSS and JavaScript and the fly likes Form Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Form Validation" Watch "Form Validation" New topic
Author

Form Validation

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
I am working on a form validator script that will check all the form components with ease with a new type of error notification. Right now I am building a list of validations just for text inputs. Here is a list I have and will update it. This is a rather large project!
If you notice anything I should add to this list for text boxes. Right now I am ignoring drop downs, check boxes, radios etc. That is in my next step of the program.

Already Coded:
--Test Numerical Input Only
--Test Alphabetical Input Only
--Test String Length
--Test for Empty
--Test Number Range (MIN - MAX) (MIN only ) (MAX only)
--Allow Only Certain Characters
--Test for Alphabetical & Numerical Combo Input
--Test 12 Hour Time - ability for (AM|PM)
--Test 24 Hour Time
--Test SSN Format
--Check Color HEX
--Test US Zip Code XXXXX or XXXXX-XXXX
--Test Equal to
--Email Basic Check X@X.XX
--Money Format
Functions To Add:
--Phone Number (Partially Coded)
--Number Decimals (L,R)
--Check Valid Date Format & if act. date(Partially Coded)
--Check Date Range
--Test Number of Words (MIN - MAX) (MIN) (MAX)

Thank You
Eric
[ April 21, 2003: Message edited by: Eric Pascarello ]
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
You should check out the Struts Validator (part of Jakarta Struts), it can validate input on the client-side and/or serverside. It supports a good number of configurable validations and it is easily extensible if you want to add custom validations. Overall, it is very useful and you may get some ideas for your own work.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
As an aside. Please don't forget to make all of the locale-specific validations (currency, date format, postal code, phone number format etc.) overridable, switchable or non-mandatory if you wish your code to be useful on the real (global) internet.
On of my favourite complaints is web sites which offer services world wide but force customers to choose a US state, or won't accept non-digits in a postal code, or assume all phone numbers are US-domestic, or wont allow accented characters in "letter" fields. And don't get me started on the confusion engendered by assuming I'll naturally want to enter a date in an ass-backwards month/day/year format.
Grin, but through gritted teeth
Back to your original question:
Validating a credit card number might be handy. The algorithm is described here at the ranch somewhere. Similarly, validating a pair of date fields as a duration where the "end" must be after the "start" might be neat.
Good luck.


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
I have the date one already for another script, right now I am working to figure out all of the other formats, I was going to post a question in the MD to get these types of questions on format.
Right now you can easily pick ranges, characters, currency, etc. My goal with this is to make it very friendly to the www and make it even easier for a person to add this to a form. I am sure when I finally get the first version up for testing, I am going to get yelled at for not execpting certain formats.
Thanks For your input..Any other ideas are welcomed!
Eric
 
 
subject: Form Validation
 
Threads others viewed
Pro in designing user interface
I wanted to write a method that would return the year with the most number of hits as part of ex 4.3
Parsing a date from arbitrary text.
Help coding
on checking validity of input. problem on my if-else.
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture