Regular expression Validation _ regular expression

Source: Internet
Author: User

<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1294368471619564&dt=1150677702359&lmt=1150677702&format=250x250_as&output=html&url=http%3A%2F%2Fwww.manbu.net%2FLib%2FClass1%2FSub11%2F1%2F8.asp&color_bg=ECF8FF&color_text=6F6F6F&color_link=0000CC&color_url=008000&color_border=B4D0DC&ad_type=text&ref=http%3A%2F%2Fwww.manbu.net%2FLib%2FClass1%2FSub11%2Findex.asp&cc=100&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_his=3" frameborder="0" width="250" scrolling="no" height="250" allowtransparency=""></iframe>#######################
# Author: Rain wave All rights reserved, duplicate say #
#qq:270499458 #
#######################

Recently some friends who have just learned regular expressions ask me how to use in ASP. Oh Although it is simple, write it, the basic knowledge of regular expressions I will not say. In fact, there are many such articles. :(

##### function Code ########
assumed to be myfunc.asp

<%
' Regular table expression validation function patrn-Regular expression strng-a string to be validated
Function regexptest (PATRN, STRNG)
Dim regEx, RetVal ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = False ' Sets whether case sensitive.
RetVal = regex.test (strng) ' performs a search test.
Regexptest = RetVal ' Returns the value, does not conform returns false, conforms to true
End Function
%>

##### Submit page Code ######
assumed to be mypage.asp

<form method= "POST" action= "check.asp" >
Please enter e-mail address: <input type=text name=email>
<br>
Please enter the phone number: <input type=text name=tel>
<input type=submit value= "OK" >
</form>

##### Validation Page ########
assumed to be check.asp

<!--#include file= "myfunc.asp"-->
<%
Tel=request.form ("tel")
Email=request.form ("email")
Dim founderr:founderr=false ' Create variable, correct or fail tag
' Everybody, by the way, I'm here to contribute a regular expression and verify the phone number and phone number!
If Regexptest ("(^[0-9]{3,4}\-[0-9]{3,8}$) | ( ^[0-9]{3,8}$) | (^\ ([0-9]{3,4}\) [0-9]{3,8}$) | (^0{0,1}13[0-9]{9}$) ", tel) =false Then
Founderr=true
regshow=regshow& "<li> The phone number you entered is not in the correct format"
End If
If Regexptest ("^[\w-]+" (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$ ", email) =false Then
Founderr=true
regshow=regshow& "<li> e-mail you entered is not in the correct format"
End If
If Founderr=false then regshow= "<li> the format you entered is correct."
%>
<br><br>
<%=regshow%>

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.