Q
申請表驗證
-2
A
回答
1
等給出如下
<script type="text/javascript">
function checkValidation(){
var mobile = document.getElementById('mobile').value;
var gome = document.getElementById('home').value;
var work = document.getElementById('work').value;
var error_count = 0;
if(mobile == ''){
error_count = error_count + 1;
}
if(home == ''){
error_count = error_count + 1;
}
if(work == ''){
error_count = error_count + 1;
}
if(error_count == 3){
alert("Please add at least one from mobile ,work,home contact no.! ");
return false;
}else{
return true;
}
}
</script>
你可以嘗試這樣的事情你可以試試代碼。
謝謝
1
我希望這會幫助你找到你想要的東西。如果你的HTML表單上提交了調用validation()函數:
<script type="text/javascript">
function validation() {
var a = document.form.phone.value;
var b = document.form.mobile.value;
var c = document.form.home.value;
if(a=="" && b =="" && c =="") {
alert("Please Enter at least one Number");
//add other validation if you need here
document.form.phone.focus(); // focus the first field for example
return false;
}
}
</script>
1
不要把輸入值與「」或「'比較。用戶可以簡單地鍵入空格。請檢查或修剪空白並檢查它是否是有效的數字。
<script type="text/javascript">
//Check for all whitespace.
function hasWhiteSpace(s){
return /^\s+$/g.test(s);
}
//Check for valid number
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function validation(){
var mobile = document.getElementById('mobile').value;
var home = document.getElementById('home').value;
var work = document.getElementById('work').value;
var error = 0;
if(!(!hasWhiteSpace(mobile) && isNumber(mobile))){
error += 1;
}
if(!(!hasWhiteSpace(home) && isNumber(home))){
error += 1;
}
if(!(!hasWhiteSpace(work) && isNumber(work))){
error += 1;
}
if(error == 3){
alert("You must enter at least one contact number.");
return false;
}else{
return true;
}
}
</script>
從窗體onsubmit調用驗證()。
<form onsubmit="return validation();">
JavaScript Check For White Space
希望這有助於
0
jQuery的情況下,你希望它
HTML:
個<form id="form1">
Home <input type="phone" class="phones"><br/>
Work <input type="phone" class="phones"><br/>
Mobile <input type="phone" class="phones"><br/>
<input type="submit">
</form>
JS:
$(function(){
$("#form1").on("submit",function() {
var notempty = $(".phones[value!='']"); // you can extend this test
if (notempty.length<1) {
alert('Please fill at least one number');
$(".phones:first").focus();
return false;
}
return true;
});
});
+0
謝謝。它的用處。 – Dipali
相關問題
- 1. Rails申請表驗證
- 2. 使用OpenCV申請表格驗證
- 3. 驗證表格日期在JavaScript申請
- 4. 申請未能協同設計驗證
- 5. 申請未能協同設計驗證
- 6. 驗證Google付款申請API
- 7. 如何使用驗證我的申請表單,在PHP
- 8. 申請表
- 9. Xero公開申請突然證書驗證失敗
- 10. 申請校驗爲char
- 11. 如何申請認證
- 12. 申請認證的配置
- 13. 簽署證書申請
- 14. WordPress的申請表
- 15. 年度申請Excel申請
- 16. 表單請求驗證JSON
- 17. 表單驗證:請選擇
- 18. Javascript或jquery驗證應用程序的日期再次申請
- 19. 申請jQuery的表單提交驗證到只有1出2提交按鈕
- 20. jquery,css不申請表
- 21. GUI學生申請表
- 22. 申請表格批准
- 23. 申請行動代表
- 24. 申請單表繼承
- 25. 無法更新申請表
- 26. XML中的申請表格
- 27. 如何申請表格
- 28. Facebook的申請表在HTML
- 29. 澤西申請頭申請失敗/ xml
- 30. iPhone開發人員證書申請
是的,有.. – Jocelyn
請清除您知道如何驗證一個,並希望條件三的驗證或想整個事情! – MJQ
@Dipali - 請接受對您有用的解決方案!它會使其他人受益。謝謝! – Usha