我有一个使用http://digitalbush.com/projects/masked-input-plugin/屏蔽并使用http://bassistance.de/jquery-plugins/jquery-plugin-validation/验证的电话号码。
代码位于下方,“几乎”工作示例位于http://jsfiddle.net/dnv38/。
请注意,电话号码不是必需的,但两个插件冲突导致需要电话号码。不久前,我以为我找到了每个jquery.maskedinput-1.3.js 与 jquery.validate 1.9.0 冲突的答案,但事实证明它不正确。
如何屏蔽输入并验证它,但不使其成为必需?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Validate</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.js" type="text/javascript"></script>
<script src="http://snort-rule-manager.googlecode.com/svn-history/r2/trunk/assets/9982dce2/jquery.maskedinput.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#phone").mask("(999) 999-9999");
var validator=$("#form").validate({
rules: {phone:"phoneUS"},
submitHandler: function(form) {
alert('submitHandler');
}
});
});
</script>
</head>
<body>
<form id="form" method="post">
<input type="text" name="phone" id="phone" value="" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>