<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jquery validation plugin - Thien An Blog</title>
	<atom:link href="https://thienanblog.com/tag/jquery-validation-plugin/feed/" rel="self" type="application/rss+xml" />
	<link>https://thienanblog.com/tag/jquery-validation-plugin/</link>
	<description>Javascript - PHP - SEO - Web Development</description>
	<lastBuildDate>Fri, 12 Jun 2015 03:51:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>

<image>
	<url>https://thienanblog.com/wp-content/uploads/2017/05/TAB_favicon.ico.png</url>
	<title>jquery validation plugin - Thien An Blog</title>
	<link>https://thienanblog.com/tag/jquery-validation-plugin/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Hướng dẫn sử dụng jQuery Validation</title>
		<link>https://thienanblog.com/javascript/jquery/huong-dan-su-dung-jquery-validation/</link>
					<comments>https://thienanblog.com/javascript/jquery/huong-dan-su-dung-jquery-validation/#respond</comments>
		
		<dc:creator><![CDATA[Ân Vũ]]></dc:creator>
		<pubDate>Thu, 11 Jun 2015 12:10:25 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[cách sử dụng jquery validate]]></category>
		<category><![CDATA[cách sử dụng jquery validation]]></category>
		<category><![CDATA[jquery validate cách sử dụng]]></category>
		<category><![CDATA[jquery validate là gì]]></category>
		<category><![CDATA[jquery validation là gì]]></category>
		<category><![CDATA[jquery validation plugin]]></category>
		<category><![CDATA[kiểm soát thông tin form]]></category>
		<category><![CDATA[kiểm tra form]]></category>
		<category><![CDATA[plugin validate jquery]]></category>
		<category><![CDATA[thư viện validate jquery]]></category>
		<category><![CDATA[thư viện validation jquery]]></category>
		<category><![CDATA[validate bằng jquery]]></category>
		<category><![CDATA[xác thực thông tin từ form]]></category>
		<category><![CDATA[xử lý form jquery]]></category>
		<guid isPermaLink="false">https://thienanblog.com/?p=116</guid>

					<description><![CDATA[<p>I. Giới thiệu và Cài đặt Tác giả: Jörn Zaefferer Website: http://jqueryvalidation.org jQuery Validation được xây dựng giúp các lập trình viên có thể xác thực được những thông tin người&#8230;</p>
<p>The post <a href="https://thienanblog.com/javascript/jquery/huong-dan-su-dung-jquery-validation/">Hướng dẫn sử dụng jQuery Validation</a> appeared first on <a href="https://thienanblog.com">Thien An Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>I. Giới thiệu và Cài đặt</h2>
<p>Tác giả: Jörn Zaefferer</p>
<p>Website: <a href="http://jqueryvalidation.org">http://jqueryvalidation.org</a></p>
<p><a href="https://thienanblog.com/wp-content/uploads/2015/06/logo.png"><img fetchpriority="high" decoding="async" class=" size-full wp-image-117 aligncenter" src="https://thienanblog.com/wp-content/uploads/2015/06/logo.png" alt="logo" width="546" height="130" srcset="https://thienanblog.com/wp-content/uploads/2015/06/logo.png 546w, https://thienanblog.com/wp-content/uploads/2015/06/logo-300x71.png 300w" sizes="(max-width: 546px) 100vw, 546px" /></a></p>
<p><strong>jQuery Validation được xây dựng giúp các lập trình viên có thể xác thực được những thông tin người dùng nhập vào Form một cách nhanh chóng và dễ dàng.</strong></p>
<p><strong>Để có thể cài đặt jQuery Validate các bạn cần thực hiện các bước sau:</strong></p>
<ol>
<li>Truy cập vào <a href="https://github.com/jzaefferer/jquery-validation">https://github.com/jzaefferer/jquery-validation</a> và nhấn vào nút “Download ZIP”.</li>
<li>Giải nén file vừa tải về, chúng ta sẽ được cấu trúc thư mục như sau:</li>
</ol>
<p><img decoding="async" class=" size-full wp-image-119 aligncenter" src="https://thienanblog.com/wp-content/uploads/2015/06/1.-Cau-truc-folder.png" alt="1. Cau truc folder" width="132" height="187" /></p>
<ol start="3">
<li>Các bạn hãy vào folder “dist” và sau đó copy file “jquery.validate.min.js”.</li>
<li>Sau đó, các bạn hãy bỏ vào folder chứa website mà chúng ta xây dựng.</li>
<li>Tiến hành thêm thư viện vào trong website của chúng ta, nhưng các bạn cũng cần phải tải thư viện jQuery tại <a href="http://jquery.com">http://jquery.com</a> về trước nhé:</li>
</ol>
<p><img decoding="async" class="aligncenter wp-image-120 size-full" src="https://thienanblog.com/wp-content/uploads/2015/06/2.-Them-thu-vien-vao-HTML.png" alt="Thêm thư viện vào HTML" width="515" height="49" srcset="https://thienanblog.com/wp-content/uploads/2015/06/2.-Them-thu-vien-vao-HTML.png 515w, https://thienanblog.com/wp-content/uploads/2015/06/2.-Them-thu-vien-vao-HTML-300x29.png 300w" sizes="(max-width: 515px) 100vw, 515px" /></p>
<ol start="6">
<li>(Tùy chọn) Nếu như các bạn không thích tải về thư viện jQuery Validation hoặc kể cả jQuery, các bạn có thể dùng các đường link CDN sau đây:</li>
</ol>
<pre class="lang:default decode:true">&lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"&gt;&lt;/script&gt;</pre>
<ol start="7">
<li>Cài đặt hoàn tất.</li>
</ol>
<h2>II. Sử dụng</h2>
<p>Để sử dụng jQuery Validation các bạn cần phải biết qua phương thức “$(‘#id_cua_form’).validate()” (Nếu dùng class thì các bạn hãy tự thay thế). Chúng ta sẽ có cấu trúc HTML đơn giản như sau:</p>
<pre class="lang:default decode:true ">&lt;form method="get" accept-charset="utf-8" style="width:600px;margin: 0px auto;" id="formDemo"&gt;
		&lt;fieldset&gt;
			&lt;legend&gt;Demo jQuery Validation - ThienAnBlog.com&lt;/legend&gt;
			&lt;div&gt;
				&lt;label&gt;Họ&lt;/label&gt;
				&lt;input name="ho" type="text" placeholder="Vui lòng nhập họ" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Tên&lt;/label&gt;
				&lt;input name="ten" type="text" placeholder="Vui lòng nhập tên" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Địa chỉ&lt;/label&gt;
				&lt;input name="diachi" type="text" placeholder="Vui lòng nhập địa chỉ" required&gt;
			&lt;/div&gt;
			&lt;button type="submit"&gt;Gửi&lt;/button&gt;
		&lt;/fieldset&gt;
	&lt;/form&gt;</pre>
<p>Và cấu trúc thẻ &lt;script&gt;:</p>
<pre class="lang:default decode:true">$(document).ready(function() {

		//Khi bàn phím được nhấn và thả ra thì sẽ chạy phương thức này
		$("#formDemo").validate({
			rules: {
				ho: "required",
				ten: "required",
				diachi: {
					required: true,
					minlength: 2
				}
			},
			messages: {
				ho: "Vui lòng nhập họ",
				ten: "Vui lòng nhập tên",
				diachi: {
					required: "Vui lòng nhập địa chỉ",
					minlength: "Địa chỉ ngắn vậy, chém gió ah?"
				}
			}
		});
	});</pre>
<p>Khi chạy nó, các bạn sẽ thấy thư viện của chúng ta sẽ thực hiện “Xác thực” (Validate) khi chúng ta nhấn vào nút “Submit” thì ở đây nó chính là nút “Gửi”. Hoặc các bạn có thể gõ vài dòng chữ vào và nhận ra sự khác biệt khi xóa đi. Đó chính là những đoạn thông báo nhỏ như sau:</p>
<p><a href="https://thienanblog.com/wp-content/uploads/2015/06/3.-Form-Validate-Simple.png"><img loading="lazy" decoding="async" class=" size-full wp-image-121 aligncenter" src="https://thienanblog.com/wp-content/uploads/2015/06/3.-Form-Validate-Simple.png" alt="Form Validate - Simple" width="607" height="126" srcset="https://thienanblog.com/wp-content/uploads/2015/06/3.-Form-Validate-Simple.png 607w, https://thienanblog.com/wp-content/uploads/2015/06/3.-Form-Validate-Simple-300x62.png 300w" sizes="auto, (max-width: 607px) 100vw, 607px" /></a></p>
<p>Rất là đẹp mắt phải không các bạn? Nhưng thật ra để được vậy thì các bạn phải có CSS vào nữa đấy chứ thật ra Form này khi không có CSS thì các bạn sẽ thấy nó chạy lung tung.</p>
<p>Tôi sẽ giải thích một tí về đoạn script mà chúng ta viết:</p>
<ol>
<li>Phương thức &#8220;<strong>validate()</strong>&#8221; chấp nhận 1 đối số là <strong>một đối tượng</strong> có <strong>2 thuộc tính</strong> chính là “<strong>rules</strong>” và “<strong>messages</strong>”.</li>
<li>Trong đó, “<strong>rules</strong>” đại diện cho điều kiện xác thực như “<strong>required</strong>”(Không bỏ trống), “<strong>minlength</strong>”(Độ dài tối thiểu)…và “<strong>messages</strong>” đại diện cho các thông báo lỗi mà chúng ta đã thấy ở ví dụ trên.</li>
<li>Và thuộc tính “<strong>rules</strong>” của chúng ta sẽ lại bao gồm các phần tử con cũng là <strong>một đối tượng</strong> với các thuộc tính bên trong nó chính là thuộc tính “<strong>name</strong>” bên trong các thẻ “<strong>input</strong>” của chúng ta. Các bạn có thể xem qua hình ảnh sau:</li>
</ol>
<p><a href="https://thienanblog.com/wp-content/uploads/2015/06/4.-So-sanh-HTML-va-Code.png"><img loading="lazy" decoding="async" class=" size-full wp-image-128 aligncenter" src="https://thienanblog.com/wp-content/uploads/2015/06/4.-So-sanh-HTML-va-Code.png" alt="So sanh HTML va Code" width="594" height="286" srcset="https://thienanblog.com/wp-content/uploads/2015/06/4.-So-sanh-HTML-va-Code.png 594w, https://thienanblog.com/wp-content/uploads/2015/06/4.-So-sanh-HTML-va-Code-300x144.png 300w" sizes="auto, (max-width: 594px) 100vw, 594px" /></a></p>
<ol start="4">
<li>Rất đơn giản phải không nào? “<strong>messages</strong>” cũng sẽ <strong>tương tự</strong> “<strong>rules</strong>” và nếu bạn tinh ý sẽ nhận ra là kể cả điều kiện bên trong nó như “<strong>required</strong>”, “<strong>minlength</strong>” cũng sẽ tương đồng với bên “<strong>messages</strong>”. Hai cái chỉ khác nhau về công việc mà thôi.</li>
<li>Như vậy, chúng ta đã hoàn tất được công việc “Validate” rồi đấy.</li>
</ol>
<p>Chúng ta sẽ có cấu trúc hoàn chỉnh như sau:</p>
<pre class="lang:default decode:true">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta charset="utf-8"&gt;
	&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
	&lt;title&gt;jQuery Validation - ThienAnBlog.com&lt;/title&gt;	
	&lt;style type="text/css"&gt;
	label {
		display: inline-block;
		width: 150px;
	}
	input[type="text"], input[type="password"] {
		display: inline-block;
		width: 200px;
	}
	label.error {
		display: inline-block;
		color:red;
		width: 200px;
	}
	&lt;/style&gt;
	&lt;!-- Load Thư viện jQuery vào trước khi load jQuery Validate--&gt;
	&lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
	&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;form method="get" accept-charset="utf-8" style="width:600px;margin: 0px auto;" id="formDemo"&gt;
		&lt;fieldset&gt;
			&lt;legend&gt;Demo jQuery Validate - ThienAnBlog.com&lt;/legend&gt;
			&lt;div&gt;
				&lt;label&gt;Họ&lt;/label&gt;
				&lt;input name="ho" type="text" placeholder="Vui lòng nhập họ" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Tên&lt;/label&gt;
				&lt;input name="ten" type="text" placeholder="Vui lòng nhập tên" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Địa chỉ&lt;/label&gt;
				&lt;input name="diachi" type="text" placeholder="Vui lòng nhập địa chỉ" required&gt;
			&lt;/div&gt;
			&lt;button type="submit"&gt;Gửi&lt;/button&gt;
		&lt;/fieldset&gt;
	&lt;/form&gt;
	&lt;script type="text/javascript"&gt;

	$(document).ready(function() {

		//Khi bàn phím được nhấn và thả ra thì sẽ chạy phương thức này
		$("#formDemo").validate({
			rules: {
				ho: "required",
				ten: "required",
				diachi: {
					required: true,
					minlength: 2
				}
			},
			messages: {
				ho: "Vui lòng nhập họ",
				ten: "Vui lòng nhập tên",
				diachi: {
					required: "Vui lòng nhập địa chỉ",
					minlength: "Địa chỉ ngắn vậy, chém gió ah?"
				}
			}
		});
	});
	&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Ngoài ra, tôi sẽ gửi thêm cho các bạn một file demo khác để giúp các bạn hình dung rõ ràng hơn như sau:</p>
<pre class="lang:default decode:true">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta charset="utf-8"&gt;
	&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
	&lt;title&gt;jQuery Validate - ThienAnBlog.com&lt;/title&gt;	
	&lt;style type="text/css"&gt;
	label {
		display: inline-block;
		width: 150px;
	}
	input[type="text"], input[type="password"] {
		display: inline-block;
		width: 200px;
	}
	label.error {
		display: inline-block;
		color:red;
		width: 200px;
	}
	&lt;/style&gt;
	&lt;!-- Load Thư viện jQuery vào trước khi load jQuery Validate--&gt;
	&lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
	&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;form method="get" accept-charset="utf-8" style="width:600px;margin: 0px auto;" id="formDemo"&gt;
		&lt;fieldset&gt;
			&lt;legend&gt;Demo jQuery Validate - ThienAnBlog.com&lt;/legend&gt;
			&lt;div&gt;
				&lt;label&gt;Họ&lt;/label&gt;
				&lt;input name="ho" type="text" placeholder="Vui lòng nhập họ" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Tên&lt;/label&gt;
				&lt;input name="ten" type="text" placeholder="Vui lòng nhập tên" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Địa chỉ&lt;/label&gt;
				&lt;input name="diachi" type="text" placeholder="Vui lòng nhập địa chỉ" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Số điện thoại&lt;/label&gt;
				&lt;input name="sodienthoai" type="text" placeholder="Vui lòng nhập số điện thoại" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Email&lt;/label&gt;
				&lt;input name="email" type="text" placeholder="Vui lòng nhập Email" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Mật khẩu&lt;/label&gt;
				&lt;input id="password" name="password" type="password" placeholder="Vui lòng nhập Password" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Nhập lại mật khẩu&lt;/label&gt;
				&lt;input name="confirm_password" type="password" placeholder="Vui lòng nhập lại Password" required&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Điều khoản&lt;/label&gt;
				&lt;input name="dieukhoan" type="checkbox"&gt;
			&lt;/div&gt;
			&lt;div&gt;
				&lt;label&gt;Thông tin thêm&lt;/label&gt;
				&lt;input name="thongtinthem" type="text" placeholder="Tùy chọn..."&gt;
			&lt;/div&gt;
			&lt;button type="submit"&gt;Gửi&lt;/button&gt;
		&lt;/fieldset&gt;
	&lt;/form&gt;
	&lt;script type="text/javascript"&gt;

	$(document).ready(function() {

		//Khi bàn phím được nhấn và thả ra thì sẽ chạy phương thức này
		$("#formDemo").validate({
					rules: {
						ho: "required",
						ten: "required",
						diachi: {
							required: true,
							minlength: 2
						},
						sodienthoai: {
							required: true,
							minlength: 5
						},
						password: {
							required: true,
							minlength: 5
						},
						confirm_password: {
							required: true,
							minlength: 5,
							equalTo: "#password"
						},
						email: {
							required: true,
							email: true
						},
						dieukhoan: "required"
					},
					messages: {
						ho: "Vui lòng nhập họ",
						ten: "Vui lòng nhập tên",
						diachi: {
							required: "Vui lòng nhập địa chỉ",
							minlength: "Địa chỉ ngắn vậy, chém gió ah?"
						},
						sodienthoai: {
							required: "Vui lòng nhập số điện thoại",
							minlength: "Số máy quý khách vừa nhập là số không có thực"
						},
						password: {
							required: 'Vui lòng nhập mật khẩu',
							minlength: 'Vui lòng nhập ít nhất 5 kí tự'
						},
						confirm_password: {
							required: 'Vui lòng nhập mật khẩu',
							minlength: 'Vui lòng nhập ít nhất 5 kí tự',
							equalTo: 'Mật khẩu không trùng'
						},
						email: {
							required: "Please provide a password",
							minlength: "Your password must be at least 5 characters long",
							equalTo: "Please enter the same password as above"
						},
						email: "Vui lòng nhập Email",
						agree: "Vui lòng đồng ý các điều khoản"
					}
				});
	});
	&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Các bạn có thể tải các <a href="https://thienanblog.com/wp-content/uploads/2015/06/demo.zip">Demo trên tại đây</a>.</p>
<h2>Một số điều kiện bên trong jQuery Validation</h2>
<table>
<tbody>
<tr>
<td width="312">required</td>
<td width="312">Không được bỏ trống</td>
</tr>
<tr>
<td width="312">remote</td>
<td width="312">Gửi yêu cầu về Web Server để xác thực</td>
</tr>
<tr>
<td width="312">minlength</td>
<td width="312">Độ dài tối thiểu</td>
</tr>
<tr>
<td width="312">maxlength</td>
<td width="312">Độ dài tối đa</td>
</tr>
<tr>
<td width="312">rangelength</td>
<td width="312">Độ dài tối thiểu từ x tới y</td>
</tr>
<tr>
<td width="312">min</td>
<td width="312">Số tối thiểu</td>
</tr>
<tr>
<td width="312">max</td>
<td width="312">Số tối đa</td>
</tr>
<tr>
<td width="312">range</td>
<td width="312">Số tối thiểu từ x tới y</td>
</tr>
<tr>
<td width="312">email</td>
<td width="312">Xác thực định dạng Email</td>
</tr>
<tr>
<td width="312">url</td>
<td width="312">Xác thực định dạng URL</td>
</tr>
<tr>
<td width="312">date</td>
<td width="312">Xác thực định dạng ngày tháng</td>
</tr>
<tr>
<td width="312">dateISO</td>
<td width="312">Xác thực định dạng ngày tháng theo chuẩn ISO</td>
</tr>
<tr>
<td width="312">number</td>
<td width="312">Phải là số, bao gồm số thập phân</td>
</tr>
<tr>
<td width="312">digits</td>
<td width="312">Chỉ chấp nhận số nguyên dương</td>
</tr>
<tr>
<td width="312">creditcard</td>
<td width="312">Xác thực số thẻ tín dụng</td>
</tr>
<tr>
<td width="312">equalTo</td>
<td width="312">Phải trùng với phần tử nào đó</td>
</tr>
</tbody>
</table>
<p>Ngoài ra, các bạn có thể tham khảo tại đây <a href="http://jqueryvalidation.org/documentation">http://jqueryvalidation.org/documentation</a> để có thể tìm hiểu thêm về thư viện này.</p>
<p>The post <a href="https://thienanblog.com/javascript/jquery/huong-dan-su-dung-jquery-validation/">Hướng dẫn sử dụng jQuery Validation</a> appeared first on <a href="https://thienanblog.com">Thien An Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thienanblog.com/javascript/jquery/huong-dan-su-dung-jquery-validation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
