Learn how to use regular expressions in ASP using a few examples

Source: Internet
Author: User
Tags continue
Regular Http://www.asp888.net Tofu Technology Station

Learn how to use regular expressions in ASP using a few very practical examples

We know that in VBscript 5.0 we start to support regular expressions, and here we use several common application examples to help us
Understand and use this good program writing format
1 First, the rule of password verification is that the first letter of the password cannot be a number, and the length of the password is between 4 and 16.
And the password can only contain characters, numbers, and underscores

Let us not consider whether such a restriction makes sense, and our task is to learn regular expressions
Function ValidatePassword (strpassword)
' Http://www.asp888.net Tofu Technology Station
' Tofu production is a boutique
Dim RE
Set re = new REGEXP
Re. IgnoreCase = False
Re.global = False
Re. Pattern = "^[a-za-z]\w{3,15}$"
ValidatePassword = Re. Test (strpassword)
End Function
Explain
The ^ symbol indicates that the rule behind the connection is the processing limit for the first character, and he must be in accordance with the rules determined by [a-za-z]
The rule of [a-za-z] is--"[" means from start "]" to end
{and} represent no (and) representations containing
The rules for the expression of characters, numbers and underscores are \w
In accordance with this rule, we continue to look at an Email address of the inspection rules adopted
2.Email Address Inspection
<%
Function validateemailaddr (STREMAILADDR)
' Http://www.asp888.net Tofu Technology Station
' Tofu production is a boutique
' Webmaster@asp888.net
Dim RE
Set re = new REGEXP
Re.pattern = "^\w+@[a-za-z_]+?\." [A-za-z] {2,3}$ "
Validateemailaddr=re. Test (STREMAILADDR)
End Function
%>
This email inspection rule is what we use in general to detect rules for mail addresses

Through these two examples, we have a simple understanding of the powerful functions of regular expressions in practical applications, and, of course, since they are powerful
It is absolutely impossible in an article to talk about the huge, we can continue to explore this issue, welcome to send a letter with tofu contact
Webmaster@asp888.net



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.