Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- A Universal Script for Javascript Form Validation


Dabrowski - 4:52 pm on Oct 3, 2008 (gmt 0)


assumption is that you wanted something simple that anyone could use

Correct. Although I will add regex, that way an experienced coder could still use the script but hopefully customise it to his liking.

I've now got a very large test form, and some working code, and I've started to put the basics together.

I've been thinking about how to actually tell the script which boxes are which. I've come up with 2 possibilities so far, one of which will make you all shout at me a lot I think.

Idea 1 - hidden form fields:
<input type='hidden' name='formconfig' value='yourname; required; type, letters, allow, spaces; transform, capitalize'>

...

<input type='text' name='yourname'>

So basically the value string contains:
yourname - name of input box
required - will error on submit if not filled in
type, letters, allow, spaces - tells it to accept letters but allow spaces
transform, capitalize - capitalize the name, e.g. user types "john doe", changes to "John Doe".

With ; and , being major and minor command separators (which I've already added a way to change ;) ).

Idea 2 ... bring the fire ... an invalid property:
<input type='text' name='yourname' validate='required; type, letters, allow, spaces; transform, capitalize'>

I realise that's probably not 100% compatible, but I'm sure I've used that method before for something and it worked ok. I believe the W3C does say somewhere that any non standard properties should be added to the element?


Thread source:: http://www.webmasterworld.com/javascript/3749043.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com