Skip to content

Commit

Permalink
refactoried
Browse files Browse the repository at this point in the history
  • Loading branch information
XiupengMa committed Aug 9, 2013
1 parent cec0ba9 commit a189423
Showing 7 changed files with 756 additions and 257 deletions.
543 changes: 543 additions & 0 deletions libs/VldRulesLib-1.0.1.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion libs/VldRulesLib.js
Original file line number Diff line number Diff line change
@@ -641,7 +641,6 @@ define("VldRulesLib",[''],function(require,exports,module){
}
},


/*
* 规则解析函数,将复合规则解析成object
* @param:rule {string} 规则语句
15 changes: 15 additions & 0 deletions libs/sea.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions samples/sample.html
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
<option value="mobile">手机</option>
<option value="url">URL</option>
<option value="alphanumeric">字母数字</option>
<option value="alphanumeric_space">字母数字空格</option>
<option value="alphanumeric_underline">字母数字空格</option>
<option value="number">数字</option>
<option value="alpha_space">字母空格</option>
<option value="alpha_underline">字母空格</option>
<option value="lt[10]">小于10</option>
<option value="gt[10]">大于10</option>
<option value="equal[10]">等于10</option>
@@ -39,7 +39,7 @@
<input type="button" id="submit" name="submit" value="验证"/>
</div>
<script type="text/javascript" src="../libs/jquery-2.0.1.js"></script>
<script type="text/javascript" src="../libs/VldRulesLib.js"></script>
<script type="text/javascript" src="../libs/VldRulesLib-1.0.1.js"></script>
<script type="text/javascript" src="sample.js"></script>
</body>
</html>
23 changes: 12 additions & 11 deletions samples/sample.js
Original file line number Diff line number Diff line change
@@ -5,24 +5,25 @@ $(document).ready(function() {
msgDiv.hide();
$("#submit").bind("click", function() {
var data = input.value;
var rule = select.value;
var rule = select.value.split("&");
//调用格式 VldRulesLib.validate(value,rule,success,fail)
var result = VldRulesLib.validate(data, rule, "passed", "failed", function(value, rule, results) {
var result = VldRulesLib.validate(data, rule);
if(result.passed){
ok(result.revisedVal);
} else {
error(result.revisedVal);
}
function ok(value, rule, results) {
console.log('success!');
console.log(value);
console.log(rule);
console.log(results);
}, function(value, rule, results) {
}
function error(value, rule, results) {
console.log('fail');
console.log(value);
console.log(rule);
console.log(results);
});
}
var html = [];
html.push("<b>通过: " + result.result + "</b><br/>");
html.push("<b>通过: " + result.passed + "</b><br/>");
html.push("<span>修正后数据:" + result.revisedVal + "</span><br/>");
html.push("<span>代码: " + result.code + "</span><br/>");
html.push("<span>消息: " + result.msg + "</span>");
msgDiv.html(html.join(""));
msgDiv.show();
});
2 changes: 1 addition & 1 deletion tests/UT.html
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script type="text/javascript" src="../libs/jquery-2.0.1.js"></script>
<script type="text/javascript" src="../libs/VldRulesLib.js"></script>
<script type="text/javascript" src="../libs/VldRulesLib-1.0.1.js"></script>
<script type="text/javascript" src="../libs/qunit-1.12.0.js"></script>
<script type="text/javascript" src="UT.js"></script>
</body>
Loading

0 comments on commit a189423

Please sign in to comment.