Determines whether the input information is null and the input information

Source: Internet
Author: User

Determines whether the input information is null and the input information
In the data room charging system, we need to repeat the text box and the combo box to make sure that it is not empty. There are two conditions for this judgment: first, determines whether the combo box of all text boxes in the form is empty. The second type determines whether a part of the text box is empty. For card numbers and student numbers, we need to determine whether the user inputs a number. Almost every form needs to make a similar judgment, which is written one by one. I am familiar with the Code. However, this method does not seem so clever. At this time, we can define a class for judgment. The form using this function can directly call the method in the class. Next, let's briefly introduce how to implement it.

First, check whether all text boxes and combo boxes in the form are empty;

<Span style = "font-size: 18px;"> Imports System. windows. forms '************************************** * ******* 'file Name: verdict 'namespace: Ui' internal capacity: 'function: determines whether the user input is empty, and whether the input username and a series of text boxes are numbers' file relations: & apos; Author: Ding Guohua & apos; group: Baby scheduler; generated on: 10:32:09 & apos; version: V2.0 & apos; Modify log: & apos; Copyright: '*************************************** * ***** Public Class verdict ''' <summary> ''' determines whether all text boxes and the input content of the combo box in the form are empty, if the form contains a text box or combo box that can be empty, ''' cannot be used. </summary> ''' <Param name = "frm"> </param> ''' <returns> </returns> ''' <remarks> </remarks> Public Shared Function IsAllEmptyText (ByVal frm form) as Boolean Dim control As New Control For Each control In frm. controls 'traverse all Controls in the form If TypeOf control Is TextBox then' to determine whether the control Is a text box If control. text. trim = "" Then "determines whether the content of the text box is empty MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") control. focus () Return True Exit Function End If ElseIf TypeOf control Is ComboBox Then 'determines whether the control Is a combo box If control. text. trim = "" Then MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") Return True Exit Function End If Next Return False End Function </span>
Then, judge whether some text boxes and combo boxes are empty;

<Span style = "font-size: 18px; "> ''' <summary> ''': determines whether the Text attribute of the control in the control array is null ''' </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 'traverses all elements In the array If TypeOf control Is TextBox then' to determine whether the control Is a text box If Control. text. trim = "" T Comment 'to determine whether the text box content is empty MsgBox (control. Tag. ToString + "cannot be blank! ", VbOKOnly," tip ") control. focus () Return True Exit Function End If ElseIf TypeOf control Is ComboBox Then 'determines whether the control Is a combo box If control. text. trim = "" Then MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") Return True Exit Function End If Next Return False End Function </span>
Finally, determine whether it is a number;

<Span style = "font-size: 18px; "> ''' <summary> ''' determines whether the input is a number ''' </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 'traverses all elements In the array If TypeOf control Is TextBox then' to determine whether the control Is a TextBox 'if Control. text. trim = "" then': determines whether the content of the text box is Null If IsNumeric (control. Text) = False Then 'msgbox (control. Tag. ToString + "cannot be blank! ", VbOKOnly," tip ") MsgBox (control. tag. toString + "" + "enter a number", vbOKOnly, "prompt") control. focus () control. text = "" Return False Exit Function End If Next Return True End Function </span>
Next, let's take the basic data settings in the data room charging system as an example to see how we call them;

<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>
Abstract The public part and write it into a class. The other forms are called directly, which is convenient and simple. The second version of the data center charging system is not complete and will be continued ......

 


Jquery determines whether it is empty, and then displays the prompt information. How should I write it?

Your html code needs to be modified, mainly because there is a problem in the span.
<Input id = "pwd" type = "password"/> <span class = "Error"> </span>
<Input id = "repwd" type = "password"/> <span class = "REERROR"> </span>

Below is the js Judgment program

<Script>
$ (Function (){
Var pwd = $ ("# pwd ");
Var repwd = $ ("# repwd ");
Var error = $ ('. error ');
Var reerror = $ ('. reerror ');
If (pwd. val () = ''){
Error.html ('<font color = "red"> sorry, the password cannot be blank! </Font> ');
Return false;
} Else if (repwd. val () = ''){
Reerror.html ('<font color = "red"> sorry, repeated passwords cannot be blank! </Font> ');
Return false;
} Else if (repwd. val ()! = Pwd. val ()){
Reerror.html ('<font color = "red"> sorry, the two passwords are inconsistent! </Font> ');
Error.html ('<font color = "red"> sorry, the two passwords are inconsistent! </Font> ');
Return false;
} Else {
Return true;
}
})
</Script>

========================================================== ========================
If you must use each for writing, it is also possible. First, the class behind the span has fewer quotation marks and you need to modify it.

<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 () =... the remaining full text>

How can I determine whether the input is null in C?

ACM

# Include <iostream>
# Incldue <cstdlib>
Using namespace std;

Int main ()
{
Int a, B;
While (cin> a> B)
Cout <a + B <endl;

}

That's all.

Or change to while
While (scanf (% d, & a, & B ))! = EOF)

Scanf () specifies a space between two numbers.

However, using cin can eliminate the need to consider the strong io stream of c ++.
But scanf is much faster than cin.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.