判斷輸入資訊是否為空白,判斷輸入資訊

來源:互聯網
上載者:User

判斷輸入資訊是否為空白,判斷輸入資訊
       在機房收費系統中,我們需要對文字框和組合框重複進行判斷,確保不為空白;該判斷有兩種情況,第一種,判斷表單中所有文字框組合框是否為空白,第二種,判斷一部分文字框,組合框是否為空白。對於卡號和學號等我們需要判斷使用者輸入的是否是數字,幾乎每個表單都需要進行相類似的判斷,一個一個去寫,熟悉了代碼沒錯,可是,這個方法似乎不是那麼聰明哈,這個時候,我們就可以定義一個類,專門用來進行判斷,使用該功能的表單直接調用類中的方法即可。接下來,簡單介紹一下,該如何?。

       首先,判斷表單中所有文字框、組合框是否為空白;

        

<span style="font-size:18px;">Imports System.Windows.Forms'**********************************************'文 件 名: verdict'命名空間: UI'內    容:'功    能: 判斷使用者輸入是否為空白,判斷輸入的使用者名稱等一系列是數位文字框是否是數字'檔案關係:'作    者:丁國華'小    組:寶貝計劃'產生日期: 2014/8/5 10:32:09'版本號碼:V2.0'修改日誌:'著作權說明:'**********************************************Public Class verdict    ''' <summary>    ''' 判斷表單中所有文字框、組合框輸入內容是否為空白,若表單中有允許為空白的文字框或組合框,      '''則不能使用此函數     ''' </summary>    ''' <param name="frm"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Public Shared Function IsAllEmptyText(ByVal frm As Form) As Boolean        Dim control As New Control        For Each control In frm.Controls '遍曆表單中所有的控制項              If TypeOf control Is TextBox Then '判斷控制項是不是文字框                  If control.Text.Trim = "" Then '判斷文字框內容是否為空白                      MsgBox(control.Tag.ToString + "不可為空!", vbOKOnly, "溫馨提示")                    control.Focus()                    Return True                    Exit Function                End If            ElseIf TypeOf control Is ComboBox Then '判斷控制項是不是組合框                  If control.Text.Trim = "" Then                    MsgBox(control.Tag.ToString + "不可為空!", vbOKOnly, "溫馨提示")                    Return True                    Exit Function                End If            End If        Next        Return False    End Function</span>
        接著,判斷一部分文字框、組合框是否為空白;

         

<span style="font-size:18px;"> ''' <summary>    ''' 判斷控制項數組中的控制項的Text屬性是否為空白      ''' </summary>    ''' <param name="arrayControl"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Public Shared Function IsSomeEmptyText(ByVal arrayControl() As Control) As Boolean        Dim control As New Control        For Each control In arrayControl '遍曆數組中所有元素              If TypeOf control Is TextBox Then '判斷控制項是不是文字框                  If control.Text.Trim = "" Then '判斷文字框內容是否為空白                      MsgBox(control.Tag.ToString + "不可為空!", vbOKOnly, "溫馨提示")                    control.Focus()                    Return True                    Exit Function                End If            ElseIf TypeOf control Is ComboBox Then '判斷控制項是不是組合框                  If control.Text.Trim = "" Then                    MsgBox(control.Tag.ToString + "不可為空!", vbOKOnly, "溫馨提示")                    Return True                    Exit Function                End If            End If        Next        Return False    End Function</span>
          最後,判斷是否為數字;

          

<span style="font-size:18px;"> ''' <summary>    ''' 判斷輸入的是否為數字    ''' </summary>    ''' <param name="arrayControl"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Public Shared Function IsNumberic(ByVal arrayControl() As Control) As Boolean        Dim control As New Control        For Each control In arrayControl '遍曆數組中所有元素              If TypeOf control Is TextBox Then '判斷控制項是不是文字框                  'If control.Text.Trim = "" Then '判斷文字框內容是否為空白                  If IsNumeric(control.Text) = False Then                    'MsgBox(control.Tag.ToString + "不可為空!", vbOKOnly, "溫馨提示")                    MsgBox(control.Tag.ToString + "   " + "請輸入數字", vbOKOnly, "提示")                    control.Focus()                    control.Text = ""                    Return False                    Exit Function                End If            End If        Next        Return True    End Function</span>
         緊接著,我們以機房收費系統中,基本資料設定為例,看看我們是如何進行調用的;

        

<span style="font-size:18px;">        Dim arrayControl() As Control        ReDim Preserve arrayControl(4)        arrayControl(0) = txtRate        arrayControl(1) = txtUnittime        arrayControl(2) = txtLeasttime        arrayControl(3) = txtPretime        arrayControl(4) = txtLimitcash        If verdict.IsSomeEmptyText(arrayControl) Then            Exit Sub        End If        If verdict.IsNumberic(arrayControl) = False Then            Exit Sub        End If</span>
         把公用需要使用的部分,抽象出來寫成一個類,其餘的表單直接進行調用,這樣方便,簡單,第二版機房收費系統,未完,待續......

 


jquery判斷是否為空白,然後顯示提示資訊應該怎寫?

你的html代碼需要修改下,主要是span裡面寫的有問題
<input id="pwd" type="password" /><span class="Error"></span>
<input id="repwd" type="password" /><span class="REERROR"></span>

下面是js判斷程式

<script>
$(function(){
var pwd = $("#pwd");
var repwd = $("#repwd");
var error = $('.Error');
var reerror = $('.REERROR');
if(pwd.val() == '') {
error.html('<font color="red">對不起,密碼不可為空!</font>');
return false;
} else if(repwd.val() == ''){
reerror.html('<font color="red">對不起,重複密碼不可為空!</font>');
return false;
} else if(repwd.val() != pwd.val()){
reerror.html('<font color="red">對不起,兩次密碼輸入不一致!</font>');
error.html('<font color="red">對不起,兩次密碼輸入不一致!</font>');
return false;
} else {
return true;
}
})
</script>

=========================================================
如果你一定要用each來寫,也是可以的,首先那個span後面的class你的引號少了,要修改

<input id="pwd" type="password" /><span class="Error"></span>
<input id="repwd" type="password" /><span class="Error"></span>

<script>
$(function(){
var error = $('.Error');
$(":password").each(function(index){
if($(this).val() ==......餘下全文>>
 
C語言中怎判定輸入是否為空白

ACM吧

#include <iostream>
#incldue <cstdlib>
using namespace std;

int main()
{
int a,b;
while(cin>>a>>b)
cout<<a+b<<endl;

}

就行了

或者while裡改成
while((scanf(%d %d,&a,&b))!=EOF)

scanf()裡規定了輸入兩個數之間是空格

而用cin可以不用管 c++的io流很強大 不需要做這種考慮
但是scanf明顯比cin快
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.