使用fValidator库进行Javascript表单验证

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: /^[a-z0-9@._-]{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)