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