Created
July 2, 2014 09:04
-
-
Save rutger1140/cfc20db7e14e2863fb99 to your computer and use it in GitHub Desktop.
jQuery validation tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>jQuery Validation plugin tests</title> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css"> | |
</head> | |
<body> | |
<form id="myform"> | |
<label for="url">Not required, URL: </label><br> | |
<input id="url" name="url"> | |
<hr> | |
<label for="inputlength">Not required, length: </label><br> | |
<input id="inputlength" name="inputlength"> | |
<hr> | |
<label for="inputlength">Not required, range: </label><br> | |
<input id="inputrange" name="inputrange"> | |
<hr> | |
<label for="inputlength">Max higher than Min : </label><br> | |
Min: <input id="inputbudgetmin" name="inputbudgetmin"> | |
Max: <input id="inputbudgetmax" name="inputbudgetmax"> | |
<br/> | |
<hr> | |
<input type="submit" value="Validate!"> | |
</form> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/additional-methods.js"></script> | |
<script> | |
// just for the demos, avoids form submit | |
jQuery.validator.setDefaults({ | |
debug: true, | |
success: "valid" | |
}); | |
$( "#myform" ).validate({ | |
rules: { | |
url: { | |
required: false, | |
url: true | |
}, | |
inputlength: { | |
required: false, | |
rangelength: [2, 6] | |
}, | |
inputrange: { | |
required: false, | |
range: [13, 23] | |
}, | |
inputbudgetmin: { | |
number: true, | |
range: function(element){ | |
var minval = 0; | |
var maxval = parseInt($("#inputbudgetmax").val(),10)-1 || 99999; | |
return [minval, maxval]; | |
} | |
}, | |
inputbudgetmax: { | |
number: true, | |
range: function(element){ | |
var minval = parseInt($("#inputbudgetmin").val(),10)+1 || 0; | |
var maxval = 99999; | |
return [minval, maxval]; | |
} | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment