---
title: "JQuery实行数据验证"
author: "ITCheng"
date: "2012-07-20T11:04:32Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2012-07-20T11:04:32Z"
id: 1601732
url: "https://itcheng.iteye.com/blog/1601732"
---

```
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="jquery.validate.messages_cn.js"></script>
<script type="text/javascript">
	$(function(){
		$("#myform").validate(
			{
				rules:{
					"username":{required:true,minlength:6} 
				},
				errorPlacement:function(error,element){
					error.appendTo(element.siblings("span"));	
				}
			}
		);
	});
</script>
<link href="css/screen.css" rel="stylesheet" type="text/css">
</head>

<body>
<form id="myform" action="#" method="get">
	<input id="username" name="username" type="text"/>
    <span></span><br />
    <input type="submit" />
</form>
</body>
</html>
```