Validate the legality of the data in a "Regular Expression object" in ASP

Source: Internet
Author: User
Tags regular expression
Validate the legality of the data in a "Regular Expression object" in ASP
When we make a website, especially a variety of e-commerce sites, first of all, we will allow users to fill out a number of forms to obtain registered users of various information, because users can enter a wide range of information, and some do not meet the requirements of the data will give our back-end ASP processing process unnecessary trouble, Even caused some security problems on the site. Therefore, before we save this information to the database of the website, we should validate the data of the information entered by these users so that the subsequent programs can be executed safely and smoothly. So we typically write an ASP's validator at the back end to analyze whether the data entered by the user is legitimate.
Perhaps someone might ask, is it possible to use JavaScript that runs on the client to verify the user's data better and faster? Indeed, this is possible in most cases, why is it most of the case? Because the javascript you write doesn't necessarily run on IE and Netscape at the same time as Microsoft's JScript is not entirely the same as JavaScript, plus some browsers are not necessarily compatible with Microsoft and Netscape, So it is likely that the client's JavaScript will not accurately verify the user input of various data, and the ASP program is running on the server side, but with your server environment, regardless of what the client browser, for your ASP program is no difference, Therefore, it is a good choice to use the backend ASP program to validate the data legality.
When using ASP to verify the validity of the data in the backend, some people to meet the different environment under the data validation, wrote a lot of functions to achieve, for example, we want to verify the user input URL address is legitimate, you can write a piece of code to individual character analysis of the user input information, To analyze the amount of information is small, it is better to do, if the analysis of the changing conditions, that can be miserable, not only to write a very long and cumbersome code, and the efficiency of the operation is extremely low, there is no good solution? Yes, that's the "Regular expression" object provided by VBScritp5.0, as long as your server has ie5.x installed, it will bring VBScript5.0. In fact, the "regular expression" is originally a patent under Unix, especially in the Perl language is the most widely used, it is because of "regular expression" powerful features, so that Microsoft slowly transfer the regular expression object to the Windows system, the use of
Regular Expression object, we can easily validate the validity of various data.
First, let's take a look at what the "regular expression" object is in VBScript, let's start with a procedure:
Function checkexp (PATRN, STRNG)
Dim regEx, Match ' establishes the variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether character case is case-sensitive.
Related Article

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.