欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用fValidator库进行Javascript表单验证

程序员文章站 2022-03-01 14:51:56
...
code:
  

<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/fValidator.js"></script>
<script type="text/javascript">
window.addEvent("domready", function() {
var myValidator = new fValidator("formId");
myValidator.register($("fieldId"), {type: "money", re: /^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/, msg: "Please insert a valid amount of money"});
myValidator.register($("cEmail"),{type: "required", re: /^[[email protected]_-]{1,}$/i, msg: "Please enter a valid Username.(at least 1 character and cannot contain space)"});
});
</script>



<form id="formId" action="#" method="POST" enctype="text/plain">
<input id="fieldId" type="text" name="name" value=""/>
<input type="text" id="cEmail" value=""/>
<input type="text" name="name" value="" id="mm" class="fValidate['required']"/>
<input type="submit" name="submit" value="ok"/>
</form>
相关标签: JavaScript HTML