Image

Need a really good form validator script

Hi guys,

I've spent the last two days sourcing the web for a javascript form validator. I'm pretty decent with php, which is why I've avoided using js for so long (I just did all my validation server-side), but I find myself in need now.

As you might guess, I've found heaps and heaps of js form validators, but none of them are quite right. In a nutshell, I'm looking for a single function that I can use <form ... onSubmit="return validate(this);"> to validate ANY form across my site. I want to check

  • presence of any data (for required fields)

  • valid date format (dd/mm/yyyy OR mm/yyyy)

  • check that an "EndDate" field is greater than a "StartDate" field

  • valid time format (h:mm or hh:mm or HH:MM)

  • valid currency format ($DD or $DD.cc)

  • valid number format (no alpha characters)

  • valid state (QLD OR NSW OR ACT OR VIC OR TAS OR NT OR SA OR WA)

  • valid 4-digit post code (exactly four numbers)

  • valid email address format

  • valid selection (from a <select> element)

  • valid choice (from either radio buttons or checkboxes)



I'd also like error messages to be condensed into a single alert window (so that if two fields are invalid, the alert window will display both error messages.

Ideally, I'd also like the script to literally highlight (with a background-color change) any invalid fields when it's run.

Does anyone know where I can find such a script. Sadly, I don't have the resources for a paid option on this. If I can't find a free one, I'll need to spend a few more days crawling the net for scripts I can reverse-engineer and re-write to meet this specification.

Any help would be greatly appreciated.