Is it impossible or am I not lucky enough to get an answer after a long search: how to validate optional fields with default value?
Hi,
I made some changes to the following example:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
- <style type="text/css">
- * { font-family: Verdana; font-size: 96%; }
- label { width: 10em; float: left; }
- label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
- p { clear: both; }
- </style>
- <script>
- $(document).ready(function(){
- $("#commentForm").validate();
- });
- </script>
- </head>
- <body>
- <form class="cmxform" id="commentForm" method="get" action="">
- <fieldset>
- <legend>A simple comment form with submit validation and default messages</legend>
- <p>
- <input id="cname" name="name" size="25" class="required" value="Name" onfocus="if (this.value == 'Name') {this.value=''}" onblur="if(this.value == '') { this.value='Name'}" />
- </p>
- <p>
- <input id="cemail" name="email" size="25" class="required email" value="Email" onfocus="if (this.value == 'Email') {this.value=''}" onblur="if(this.value == '') { this.value='Email'}" />
- </p>
- <p>
- <input id="curl" name="url" size="25" class="url" value="URL" onfocus="if (this.value == 'URL') {this.value=''}" onblur="if(this.value == '') { this.value='URL'}" />
- </p>
- <p>
- <textarea id="ccomment" name="comment" cols="35" rows="5" class="required" onfocus="if (this.value == 'Comment') {this.value=''}" onblur="if(this.value == '') { this.value='Comment'}">Comment</textarea>
- </p>
- <p>
- <input class="submit" type="submit" value="Submit"/>
- </p>
- </fieldset>
- </form>
- </body>
- </html>
I know how to add custom validation methods for the required fields Name, E-mail, and Comment. But I just don't know how to validate the optional filed URL. I've searched everywhere to no avail!
Any help is greatly appreciated!
Desparate