Created
September 13, 2013 09:35
-
-
Save aanoaa/6548526 to your computer and use it in GitHub Desktop.
This file contains hidden or 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>Makes "field" required and between 13 and 23.</title> | |
<link rel="stylesheet" href="http://jquery.bassistance.de/validate/demo/site-demos.css"> | |
</head> | |
<body> | |
<form id="myform"> | |
<label for="field">Required, minium 13, maximum 23:</label> | |
<input type="text" class="left" id="field" name="field"><br> | |
<label for="FAGIOD">date=true</label> | |
<input type="text" placeholder="YYYY-MM-DD" class="input-small error" date="true" name="FAGIOD"><br> | |
<label for="FUCATHLT">range_exp=[4,9,'NU']</label> | |
<input type="text" class="span1 error" range_exp="[4,9,'NU']" name="FUCATHLT"><br> | |
<input type="submit" value="Validate!"> | |
</form> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script> | |
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script> | |
<!--<script src="//cdn.jsdelivr.net/jquery.metadata/2.0/jquery.metadata.min.js"></script>--> | |
<script> | |
// just for the demos, avoids form submit | |
jQuery.validator.setDefaults({ | |
debug: true, | |
success: "valid" | |
}); | |
jQuery.validator.addMethod("range_exp", function(value, element, params) { | |
params = eval(params); | |
console.log("value is " + value); | |
console.log(params); | |
return this.optional(element) || ( (value >= params[0] && value <= params[1]) || value == params[2] ); | |
}, $.format("Please enter between {0} and {1} or {2}")); | |
$( "#myform" ).validate({ | |
errorElement: 'em', | |
rules: { | |
field: { | |
required: true, | |
range: [13, 23] | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
저도 흥미가 있어서 jsfiddle에 올려서 테스트해봤습니다.
http://jsfiddle.net/DXW44/