IAM工作如下:(IAM不是太瞭解jQuery的大部分)..驗證問題與一個jQuery驗證JQuery的
我無法辦到的事情如下:
- 只有字母a到z(小寫), 「 - 」(短劃線或連字符)和 「」 (空間)是允許的,
- 的 「 - 」(短劃線)以及 「」 必須輸入(空間)的字母,
- 「 - 」或「」字母不能是第一或最後 字母輸入,
- 「 - 」不能是直接相鄰或相近(之前或之後 )到「」,
- 「 - 」或「」一定不能直接相鄰(鄰近) 本身。
- 的 '電話' 號碼字段(4位區號,一個空格,7位 本地代碼)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type="text/javascript"
src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js">
</script>
<script>
$(document).ready(function(){
$("#commentForm").validate({
onfocusout: function(element) { $(element).valid(); } ,
rules: {
fullname : {
required: true,
maxlength: 14,
},
email: {
required: true,
email: true
}
},
messages: {
fullname : {
required: "Please specify your Full Name",
maxlength: "Please enter only upto 14 characters",
},
email: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of [email protected]"
}
}
});
});
</script>
</head>
<body>
<form id="commentForm" method="get" action="">
<fieldset>
<p>
<label for="fullname">Full Name</label>
<em>*</em><input id="fullname" name="fullname" size="25" class="required" maxlength="14" />
</p>
<p>
<label for="email">E-Mail</label>
<em>*</em><input id="email" name="email" size="25" class="required email" />
</p>
</fieldset>
</form>
</body>
</html>
請別人幫我實現這個..?
檢查[Documentation](http://docs.jquery.com/Plugins/Validation#Options_for_the_validate.28.29_method)。看起來你試圖達到的目標不是這個圖書館的一部分。 – SeinopSys
@ DJDavid98僅在該文檔的幫助下,我已經編寫了上述代碼..但是在閱讀該文檔之後,我不知道如何爲其他幾件事做驗證......順便說一句,請您告訴我在何處添加此方法?從這裏:http://docs.jquery.com/Plugins/Validation/Validator/addMethod – Clarsen
如果你只驗證兩個領域,我建議不使用jQuery驗證。您可以輕鬆編寫自己的代碼,以使用正則表達式驗證這兩個字段。它很簡單,並讓您更多地瞭解驗證如何工作。對不起,沒有回答你的問題。 – srijan