J.K.A.
J.K.A.

Reputation: 7404

validate url in jquery.validate.min.js

I have small form :

Following is the script where I am validating the required field for input field which is working perfectly now I want to validate url using jquery.validate.min.js.

<script type="text/javascript" >
            $(document).ready(function() {                                                      
                var container = $('#error');                
                $("#rssform").validate({                            
                    errorContainer: container,
                    errorLabelContainer: $(container),
                    meta: "validate",
                    rules: {                                          
                        feedurl: {
                            required:true                         
                        }                        
                    },
                    messages: {                
                        feedurl: {
                            required:"Please Enter the URL"                            
                        }                                                
                    }

                });

            });
        </script>

<form action="rssindex.php" method="POST" id="rssform">
                    <label>Enter the feed URL&nbsp;</label>         
                    <input type="submit" name="submit" value="GO" id="submit"/>
                </form>                

How can I do this. Any solution? Thanks

Upvotes: 1

Views: 689

Answers (1)

xdazz
xdazz

Reputation: 160933

jQuery validate plugin provide method to validate url.

Example:

$("#myform").validate({
  rules: {
    field: {
      required: true,
      url: true
    }
  }
});

For your code, add url: true to the rules.

                    feedurl: {
                        required:true,
                        url: true     //here                         
                    }                        

Upvotes: 1

Related Questions