-1

I have a form that contain input fields one for domain and one for folder name. now i want to validate these two fields before submitting the form.I am using jQuery validation plugin.

how can i validate my fields on custom build rules

1) domain url will not contain http:// or / at the end

   http://google.com wrong
   google.com/     wrong
   google.com      correct

2) folder name without any "/" at the start or at the end

   foldername/ wrong
   /foldername wrong
   foldername  correct

this is the code that i am trying.

<form id="f">
    <label for="domain">Domain</label>
    <input type="text" value="subdomainname.abc.com" id="domain" name="domain" maxlength="50" size="30">

    <label for="newfolder">Folder Name </label>
    <input type="text" name="newfolder" maxlength="50" size="30" id="newfolder">

    <input type="submit" value"configure">
</form>

this is validation

$(function() {
    var v = $('#f').validate({
        rules: {
            domain: {
                required: true
                 // custome rule 
            },
            newfolder: {
                required: true,
                // custome rule
            }
        },
        messages: {
            domain: {
                required: "Enter a valid url"
            },
            newfolder:{
                required: "Folder name incorrect"
            }
        },
        submitHandler: function(form) {
            alert('submit');

         }
    });          
});
Sparky
  • 98,165
  • 25
  • 199
  • 285
user3262732
  • 240
  • 1
  • 4
  • 15
  • You simply need to write custom methods following the documentation for the `addMethod` method and the appropriate regex. – Sparky Nov 29 '14 at 15:23

1 Answers1

1

I believe you are looking for a regular expression, here are the regular expressions you need:

URL Validation This mateches {anything}.{anything} if you need it to be {anything}.{only certain addresses} use this regexp Regexr


For the folder validation you are effectively just looking for a word use this one Regexr, even if it doesn't help you check out http://www.regexr.com it's a cool site and will help you with regular expressions. I have found it useful many times
MJPinfield
  • 796
  • 10
  • 25