简体   繁体   中英

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

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                         
                    }                        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM