Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement VBScript Verification

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to achieve VBScript verification". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Simple verification

With Visual Basic Scripting Edition, you can do a lot of form processing that you usually do on the server, or you can do work that cannot be done on the server.

This is a simple example of client-side validation. The result of the HTML code is a text box and a button. If you use Microsoft? Internet Explorer looks at the page made with the following code, and you'll see a small text box with a button next to it.

Simple verification

Simple verification

Please enter a number between 1 and 10:

This text box differs from the example in the simple example of the VBScript page in that the Value property of the text box is used to check the input value. To use the Value property of a text box, the code must reference the name of the text box.

Write the full name, that is, Document.ValidForm.Text1, every time you reference a text box. However, when you reference a form control multiple times, you can follow these steps: first declare a variable, and then use the Set statement to assign the form Document.ValidForm to the variable TheForm, so that you can reference the text box using TheForm.Text1. Regular assignment statements (such as Dim) are not valid here, and you must use Set to maintain references to objects.

Use numbers

Note that the above example directly detects whether the input value is a number: use the IsNumeric function to determine whether the string in the text box is a number. Although VBScript can automatically convert strings and numbers, it is always a good practice to detect the data subtypes of values entered by the user and to use conversion functions if necessary. When you add with the Value property of a text box, you should explicitly convert it to a number, because the plus sign (+) operator can perform not only addition but also string concatenation. For example, if Text1 contains "1" and Text2 contains "2", you will see the following results:

A = Text1.Value + Text2.Value'An is "12"

A = CDbl (Text1.Value) + Text2.Value 'An is 3

Pass the data back to the server after verification

The simple validation sample uses a normal button control. If you use the Submit control, all data is immediately transferred to the server, and the example will not see the data to check. Avoiding Submit controls allows you to examine data, but not submit it to the server. If you want to submit the data, you need to add another line of code, as follows:

When the data is entered correctly, the code calls the Submit method of the form object to pass the data to the server. Unless the data is judged to be right or wrong before it is passed to the server, the server will process the data, regardless of whether it is correct or not. You can find all the information about the Submit method and other methods on the Internet Explorer Script Object Model page.

So far, you have only seen standard HTML objects. Internet Explorer also enables you to take advantage of ActiveX? Controls (formerly known as OLE controls) and Java? Creates a page with the full functionality of the.

This is the end of "how to implement VBScript validation". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report